wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub

Showing 718 of 718 total issues

Similar blocks of code found in 3 locations. Consider refactoring.
Open

    private function loadSimilarityProfiles( SearchProfileService $service, SearchConfig $config ) {
        $service->registerFileRepository( SearchProfileService::SIMILARITY, self::CIRRUS_BASE,
            __DIR__ . '/../../profiles/SimilarityProfiles.config.php' );
        $service->registerRepository( new ConfigProfileRepository( SearchProfileService::SIMILARITY,
            self::CIRRUS_CONFIG, 'CirrusSearchSimilarityProfiles', $config ) );
Severity: Major
Found in includes/Profile/SearchProfileServiceFactory.php and 2 other locations - About 3 hrs to fix
includes/Profile/SearchProfileServiceFactory.php on lines 179..190
includes/Profile/SearchProfileServiceFactory.php on lines 309..320

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 152.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

File check_indices.py has 310 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Reconcile expected indices against live cluster state

Reconciles the state of multiple elasticsearch clusters against the expected
state of multiple wikis. The reconciliation process is accept based. Some
Severity: Minor
Found in scripts/check_indices.py - About 3 hrs to fix

    Function execute has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        public function execute() {
            $result = $this->getResult();
            $services = MediaWikiServices::getInstance();
            $engine = $services->getSearchEngineFactory()->create();
            if ( !( $engine instanceof CirrusSearch ) ) {
    Severity: Minor
    Found in includes/Api/QueryBuildDocument.php - About 3 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 execute has 84 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function execute() {
            $result = $this->getResult();
            $services = MediaWikiServices::getInstance();
            $engine = $services->getSearchEngineFactory()->create();
            if ( !( $engine instanceof CirrusSearch ) ) {
    Severity: Major
    Found in includes/Api/QueryBuildDocument.php - About 3 hrs to fix

      File Updater.php has 304 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      namespace CirrusSearch;
      
      use CirrusSearch\BuildDocument\BuildDocument;
      Severity: Minor
      Found in includes/Updater.php - About 3 hrs to fix

        Method parse has 82 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function parse( $query, KeywordFeature $feature, OffsetTracker $tracker, $startOffset = 0 ) {
                if ( $feature->greedy() ) {
                    Assert::precondition( !$feature->allowEmptyValue(),
                        "greedy keywords must not accept empty value" );
                    // XXX: we ignore value delimiter for greedy keywords
        Severity: Major
        Found in includes/Parser/QueryStringRegex/KeywordParser.php - About 3 hrs to fix

          Function deduplicateAnalysisConfig has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

              public function deduplicateAnalysisConfig( array $analysis ) {
                  // Deduplicate children first to normalize analyzer configuration.
                  foreach ( [ 'tokenizer', 'filter', 'char_filter' ] as $k ) {
                      if ( !isset( $analysis[$k] ) ) {
                          continue;
          Severity: Minor
          Found in includes/Maintenance/AnalysisFilter.php - About 3 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

          Function collectTitlesFromDB has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

              private function collectTitlesFromDB( $term ) {
                  $titles = [];
                  $found = [];
                  $titleFactory = MediaWikiServices::getInstance()->getTitleFactory();
                  $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
          Severity: Minor
          Found in includes/Query/MoreLikeTrait.php - About 3 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

          File SaneitizeJobs.php has 301 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          <?php
          
          namespace CirrusSearch\Maintenance;
          
          use CirrusSearch\Connection;
          Severity: Minor
          Found in maintenance/SaneitizeJobs.php - About 3 hrs to fix

            File AnalyzerBuilder.php has 299 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            <?php
            
            namespace CirrusSearch\Maintenance;
            
            use MediaWiki\Config\ConfigException;
            Severity: Minor
            Found in includes/Maintenance/AnalyzerBuilder.php - About 3 hrs to fix

              QueryStringRegexParser has 27 functions (exceeds 20 allowed). Consider refactoring.
              Open

              class QueryStringRegexParser implements QueryParser {
                  /**
                   * Whitespace regex including unicode and some control chars
                   */
                  private const WHITESPACE_REGEX = '/\G[\pZ\pC]+/u';
              Severity: Minor
              Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.php - About 3 hrs to fix

                Function detect has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function detect( $text ) {
                        $dirs = $this->config->getElement( 'CirrusSearchTextcatModel' );
                        if ( !$dirs ) {
                            return null;
                        }
                Severity: Minor
                Found in includes/LanguageDetector/TextCat.php - About 3 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

                Function doJob has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function doJob() {
                        $profile = $this->searchConfig
                            ->getProfileService()
                            ->loadProfileByName( SearchProfileService::SANEITIZER, $this->params['profile'], false );
                
                
                Severity: Minor
                Found in includes/Job/CheckerJob.php - About 3 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

                Function parse has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function parse( string $query, int $start, int $end ) {
                        $match = [];
                        Assert::precondition( $start < $end, '$start < $end' );
                        Assert::precondition( $end <= strlen( $query ), '$end <= strlen( $query )' );
                        $ret = preg_match( self::NEGATION, $query, $match, PREG_OFFSET_CAPTURE, $start );
                Severity: Minor
                Found in includes/Parser/QueryStringRegex/NonPhraseParser.php - About 3 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

                Function truncateField has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function truncateField( string $field, bool $keyword, int $minFieldLength, int $maxDocSize, string $statBucket ): void {
                        if ( !$this->document->has( $field ) ) {
                            return;
                        }
                        $fieldData = $this->document->get( $field );
                Severity: Minor
                Found in includes/BuildDocument/DocumentSizeLimiter.php - About 3 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

                AnalysisConfigBuilder has 26 functions (exceeds 20 allowed). Consider refactoring.
                Open

                class AnalysisConfigBuilder {
                    /**
                     * Version number for the core analysis. Increment the major
                     * version when the analysis changes in an incompatible way,
                     * and change the minor version when it changes but isn't
                Severity: Minor
                Found in includes/Maintenance/AnalysisConfigBuilder.php - About 3 hrs to fix

                  UpdateSuggesterIndex has 26 functions (exceeds 20 allowed). Consider refactoring.
                  Open

                  class UpdateSuggesterIndex extends Maintenance {
                      /**
                       * @var string language code we're building for
                       */
                      private $langCode;
                  Severity: Minor
                  Found in maintenance/UpdateSuggesterIndex.php - About 3 hrs to fix

                    Method execute has 75 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function execute() {
                            $this->disablePoolCountersAndLogging();
                    
                            $utils = new ConfigUtils( $this->getConnection()->getClient(), $this );
                    
                    
                    Severity: Major
                    Found in maintenance/UpdateOneSearchIndexConfig.php - About 3 hrs to fix

                      Function bulkResponseExceptionIsJustDocumentMissing has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                      Open

                          protected function bulkResponseExceptionIsJustDocumentMissing(
                              ResponseException $exception, $logCallback = null
                          ) {
                              $justDocumentMissing = true;
                              foreach ( $exception->getResponseSet()->getBulkResponses() as $bulkResponse ) {
                      Severity: Minor
                      Found in includes/DataSender.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

                      Function searchTextInternal has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private function searchTextInternal( $term ) {
                              // Searcher needs to be cloned before any actual query building is done.
                              $interleaveSearcher = $this->buildInterleaveSearcher();
                      
                              $qb = $this->buildFullTextSearch( $term );
                      Severity: Minor
                      Found in includes/Searcher.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

                      Severity
                      Category
                      Status
                      Source
                      Language