src/TtmServer/ElasticSearchTtmServer.php
File ElasticSearchTtmServer.php
has 519 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
<?php
declare( strict_types = 1 );
namespace MediaWiki\Extension\Translate\TtmServer;
ElasticSearchTtmServer
has 33 functions (exceeds 20 allowed). Consider refactoring. Open
Open
class ElasticSearchTtmServer
extends TtmServer
implements ReadableTtmServer, WritableTtmServer, SearchableTtmServer
{
/**
Method doQuery
has 87 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private function doQuery( string $sourceLanguage, string $targetLanguage, string $text ): array {
if ( !$this->useWikimediaExtraPlugin() ) {
// ElasticTTM is currently not compatible with elasticsearch 2.x/5.x
// It needs FuzzyLikeThis ported via the wmf extra plugin
throw new RuntimeException( 'The wikimedia extra plugin is mandatory.' );
Function parseQueryString
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
Open
private function parseQueryString( string $queryString, array $opts ): array {
$fields = $highlights = [];
$terms = preg_split( '/\s+/', $queryString );
$match = $opts['match'];
$case = $opts['case'];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method parseQueryString
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private function parseQueryString( string $queryString, array $opts ): array {
$fields = $highlights = [];
$terms = preg_split( '/\s+/', $queryString );
$match = $opts['match'];
$case = $opts['case'];
Method beginBootstrap
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public function beginBootstrap(): void {
$this->checkElasticsearchVersion();
$index = $this->getIndex();
if ( $this->updateMapping ) {
$this->logOutput( 'Updating the index mappings...' );
Method createSearch
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public function createSearch( string $queryString, array $opts, array $highlight ): Search {
$query = new Query();
[ $searchQuery, $highlights ] = $this->parseQueryString( $queryString, $opts );
$query->setQuery( $searchQuery );
Method update
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public function update( MessageHandle $handle, ?string $targetText ): bool {
if ( !$handle->isValid() || $handle->getCode() === '' ) {
return false;
}
Function doQuery
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
Open
private function doQuery( string $sourceLanguage, string $targetLanguage, string $text ): array {
if ( !$this->useWikimediaExtraPlugin() ) {
// ElasticTTM is currently not compatible with elasticsearch 2.x/5.x
// It needs FuzzyLikeThis ported via the wmf extra plugin
throw new RuntimeException( 'The wikimedia extra plugin is mandatory.' );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method createIndex
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private function createIndex( bool $rebuild ): void {
$indexSettings = [
'settings' => [
'index' => [
'number_of_shards' => $this->getShardCount(),