wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub

Showing 718 of 718 total issues

Function unify has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public static function unify( array $mustFilters, array $mustNotFilters ) {
        // We want to make sure that we execute script filters last.  So we do these steps:
        // 1.  Strip script filters from $must and $mustNot.
        // 2.  Unify the non-script filters.
        // 3.  Build a BoolAnd filter out of the script filters if there are any.
Severity: Minor
Found in includes/Search/Filters.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

Function extractSimilars has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    private function extractSimilars( $groupHead, array $candidates, $checkVariants = false ) {
        $group = [
            'text' => $groupHead,
            'variants' => []
        ];
Severity: Minor
Found in includes/BuildDocument/Completion/SuggestBuilder.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

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

<?php

namespace CirrusSearch\Parser\AST;

use CirrusSearch\Parser\AST\Visitor\Visitor;
Severity: Major
Found in includes/Parser/AST/WordsQueryNode.php and 2 other locations - About 1 hr to fix
includes/Parser/AST/PhrasePrefixNode.php on lines 1..51
includes/Parser/AST/WildcardNode.php on lines 1..52

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 119.

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

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

<?php

namespace CirrusSearch\Parser\AST;

use CirrusSearch\Parser\AST\Visitor\Visitor;
Severity: Major
Found in includes/Parser/AST/WildcardNode.php and 2 other locations - About 1 hr to fix
includes/Parser/AST/PhrasePrefixNode.php on lines 1..51
includes/Parser/AST/WordsQueryNode.php on lines 1..51

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 119.

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

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

<?php

namespace CirrusSearch\Parser\AST;

use CirrusSearch\Parser\AST\Visitor\Visitor;
Severity: Major
Found in includes/Parser/AST/PhrasePrefixNode.php and 2 other locations - About 1 hr to fix
includes/Parser/AST/WildcardNode.php on lines 1..52
includes/Parser/AST/WordsQueryNode.php on lines 1..51

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 119.

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

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

                'globo_norm' => [
                    'type' => 'mapping',
                    'mappings' => [
                        // map lots of apostrophe-like characters to apostrophe (T315118);
                        // formerly apostrophe_norm
Severity: Major
Found in includes/Maintenance/AnalysisConfigBuilder.php and 1 other location - About 1 hr to fix
includes/Maintenance/SuggesterAnalysisConfigBuilder.php on lines 64..121

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 119.

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

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

                'word_break_helper' => [
                    'type' => 'mapping',
                    'mappings' => [
                        '_=>\u0020', // a space for mw
                        ',=>\u0020', // useful for "Lastname, Firstname"
Severity: Major
Found in includes/Maintenance/SuggesterAnalysisConfigBuilder.php and 1 other location - About 1 hr to fix
includes/Maintenance/AnalysisConfigBuilder.php on lines 683..736

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 119.

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

Method loadConfigFromAPI has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function loadConfigFromAPI( $wikis, array $hashConfigFlags, $fallbackConfig ) {
        $endpoints = [];
        foreach ( $wikis as $prefix => $wiki ) {
            $iw = $this->interwikiLookup->fetch( $prefix );
            if ( !$iw || !$this->useConfigDumpApi || !$iw->isLocal() ) {
Severity: Minor
Found in includes/BaseInterwikiResolver.php - About 1 hr to fix

    Method get has 47 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function get( array $docIds, $sourceFiltering, $usePoolCounter = true ) {
            $connection = $this->getOverriddenConnection();
            $indexSuffix = $connection->pickIndexSuffixForNamespaces(
                $this->searchContext->getNamespaces()
            );
    Severity: Minor
    Found in includes/Searcher.php - About 1 hr to fix

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

          public function parse( string $query ): ParsedQuery {
              $this->reInit( $query );
              $queryLen = mb_strlen( $query );
              if ( $queryLen > self::QUERY_LEN_HARD_LIMIT ) {
                  throw new SearchQueryParseException( 'cirrussearch-query-too-long',
      Severity: Minor
      Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.php - About 1 hr to fix

        Method readLineBatch has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function readLineBatch( SplFileObject $file, bool $useIds ) {
                $titleParser = MediaWikiServices::getInstance()->getTitleParser();
                $pageStore = MediaWikiServices::getInstance()->getPageStore();
                $linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory();
                $batchSize = $this->getBatchSize();
        Severity: Minor
        Found in maintenance/UpdateWeightedTags.php - About 1 hr to fix

          Method updatePages has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function updatePages( $pages, $flags, string $updateKind = null, int $rootEventTime = null ): int {
                  // Don't update the same page twice. We shouldn't, but meh
                  $pageIds = [];
                  $pages = array_filter( $pages, static function ( WikiPage $page ) use ( &$pageIds ) {
                      if ( !in_array( $page->getId(), $pageIds ) ) {
          Severity: Minor
          Found in includes/Updater.php - About 1 hr to fix

            Method getInterwikiResults has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function getInterwikiResults( SearchQuery $query ): Status {
                    $sources = MediaWikiServices::getInstance()
                        ->getService( InterwikiResolver::SERVICE )
                        ->getSisterProjectConfigs();
                    if ( !$sources ) {
            Severity: Minor
            Found in includes/InterwikiSearcher.php - About 1 hr to fix

              Method __construct has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function __construct( SearchConfig $config, $weight, $profile ) {
                      parent::__construct( $config, $weight );
              
                      if ( isset( $profile['impact'] ) ) {
                          $this->impact = $this->getOverriddenFactor( $profile['impact'] );
              Severity: Minor
              Found in includes/Search/Rescore/GeoMeanFunctionScoreBuilder.php - About 1 hr to fix

                Method buildConfig has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function buildConfig() {
                        global $wgCirrusSearchWeights;
                
                        $page = $this->getDefaultFields();
                
                
                Severity: Minor
                Found in includes/Maintenance/MappingConfigBuilder.php - About 1 hr to fix

                  Method validate has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function validate() {
                          $this->out->outputIndented( "Validating new index is different..." );
                          if ( !$this->oldIndex->exists() ) {
                              $this->out->output( "ok\n" );
                              return Status::newGood( true );
                  Severity: Minor
                  Found in includes/Maintenance/Validators/IndexHasChangedValidator.php - About 1 hr to fix

                    Method updateIndices has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        protected function updateIndices( array $add, array $remove ) {
                            if ( !$remove ) {
                                return $this->updateFreeIndices( $add );
                            }
                    
                    
                    Severity: Minor
                    Found in includes/Maintenance/Validators/SpecificAliasValidator.php - About 1 hr to fix

                      Function __construct has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private function __construct( $repoType, $repoName, SearchConfig $config, callable $arrayLoader ) {
                              $this->wrapped = ArrayProfileRepository::lazyLoaded( $repoType, $repoName, static function () use ( $arrayLoader, $config ) {
                                  $profiles = [];
                      
                                  $allowedFields = [ 'suggest' => true, 'suggest-stop' => true ];
                      Severity: Minor
                      Found in includes/Profile/CompletionSearchProfileRepository.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

                      Function loadDocuments has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function loadDocuments( PageIdentity $title, $sourceFiltering = true ) {
                              [ $docId, $hasRedirects ] = $this->determineCirrusDocId( $title );
                              if ( $docId === null ) {
                                  return [];
                              }
                      Severity: Minor
                      Found in includes/Api/ApiTrait.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

                      Function score has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function score( \CirrusSearch\Search\SearchQuery $query ) {
                              Assert::parameter( $query->getSearchEngineEntryPoint() === $this->searchEngineEntryPoint,
                                  'query',
                                  "must be {$this->searchEngineEntryPoint} but {$query->getSearchEngineEntryPoint()} given." );
                      
                      
                      Severity: Minor
                      Found in includes/Dispatch/BasicSearchQueryRoute.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

                      Severity
                      Category
                      Status
                      Source
                      Language