wikimedia/mediawiki-extensions-Translate

View on GitHub
src/TtmServer/ElasticSearchTtmServer.php

Summary

Maintainability
F
3 days
Test Coverage

File ElasticSearchTtmServer.php has 519 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
declare( strict_types = 1 );

namespace MediaWiki\Extension\Translate\TtmServer;

Severity: Major
Found in src/TtmServer/ElasticSearchTtmServer.php - About 1 day to fix

    ElasticSearchTtmServer has 33 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ElasticSearchTtmServer
        extends TtmServer
        implements ReadableTtmServer, WritableTtmServer, SearchableTtmServer
    {
        /**
    Severity: Minor
    Found in src/TtmServer/ElasticSearchTtmServer.php - About 4 hrs to fix

      Method doQuery has 87 lines of code (exceeds 25 allowed). Consider refactoring.
      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.' );
      Severity: Major
      Found in src/TtmServer/ElasticSearchTtmServer.php - About 3 hrs to fix

        Function parseQueryString has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            private function parseQueryString( string $queryString, array $opts ): array {
                $fields = $highlights = [];
                $terms = preg_split( '/\s+/', $queryString );
                $match = $opts['match'];
                $case = $opts['case'];
        Severity: Minor
        Found in src/TtmServer/ElasticSearchTtmServer.php - About 2 hrs to fix

        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

            private function parseQueryString( string $queryString, array $opts ): array {
                $fields = $highlights = [];
                $terms = preg_split( '/\s+/', $queryString );
                $match = $opts['match'];
                $case = $opts['case'];
        Severity: Minor
        Found in src/TtmServer/ElasticSearchTtmServer.php - About 1 hr to fix

          Method beginBootstrap has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function beginBootstrap(): void {
                  $this->checkElasticsearchVersion();
                  $index = $this->getIndex();
                  if ( $this->updateMapping ) {
                      $this->logOutput( 'Updating the index mappings...' );
          Severity: Minor
          Found in src/TtmServer/ElasticSearchTtmServer.php - About 1 hr to fix

            Method createSearch has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function createSearch( string $queryString, array $opts, array $highlight ): Search {
                    $query = new Query();
            
                    [ $searchQuery, $highlights ] = $this->parseQueryString( $queryString, $opts );
                    $query->setQuery( $searchQuery );
            Severity: Minor
            Found in src/TtmServer/ElasticSearchTtmServer.php - About 1 hr to fix

              Method update has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function update( MessageHandle $handle, ?string $targetText ): bool {
                      if ( !$handle->isValid() || $handle->getCode() === '' ) {
                          return false;
                      }
              
              
              Severity: Minor
              Found in src/TtmServer/ElasticSearchTtmServer.php - About 1 hr to fix

                Function doQuery has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                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.' );
                Severity: Minor
                Found in src/TtmServer/ElasticSearchTtmServer.php - About 1 hr to fix

                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

                    private function createIndex( bool $rebuild ): void {
                        $indexSettings = [
                            'settings' => [
                                'index' => [
                                    'number_of_shards' => $this->getShardCount(),
                Severity: Minor
                Found in src/TtmServer/ElasticSearchTtmServer.php - About 1 hr to fix

                  There are no issues that match your filters.

                  Category
                  Status