wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub

Showing 691 of 718 total issues

Function validateParams has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

    private function validateParams() {
        $pageOptionCount = (int)$this->hasOption( 'page' ) + (int)$this->hasOption( 'page-list' )
            + (int)$this->hasOption( 'pageid-list' );
        if ( $pageOptionCount !== 1 ) {
            $this->fatalError( "Exactly one of --page, --page-list and --pageid-list must be used" );
Severity: Minor
Found in maintenance/UpdateWeightedTags.php - About 5 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 build has 133 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function build( SearchContext $searchContext, $term ) {
        $searchContext->addSyntaxUsed( 'full_text' );
        // Transform MediaWiki specific syntax to filters and extra
        // (pre-escaped) query string
        foreach ( $this->features as $feature ) {
Severity: Major
Found in includes/Query/FullTextQueryStringQueryBuilder.php - About 5 hrs to fix

    Function searchMulti has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function searchMulti( MSearchRequests $msearches ) {
            $searches = $msearches->getRequests();
            $contextResultsType = $this->searchContext->getResultsType();
            $cirrusDebugOptions = $this->searchContext->getDebugOptions();
            Assert::precondition( !$cirrusDebugOptions->isCirrusDumpQuery(), 'Must not reach this method when dumping the query' );
    Severity: Minor
    Found in includes/Searcher.php - About 5 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 buildCirrusSearchRequestEvent has 126 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function buildCirrusSearchRequestEvent() {
            global $wgRequest, $wgServerName;
            $webrequest = $wgRequest;
    
            // for the moment RequestLog::getRequests() is still created in the
    Severity: Major
    Found in includes/RequestLogger.php - About 5 hrs to fix

      Method searchMulti has 125 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function searchMulti( MSearchRequests $msearches ) {
              $searches = $msearches->getRequests();
              $contextResultsType = $this->searchContext->getResultsType();
              $cirrusDebugOptions = $this->searchContext->getDebugOptions();
              Assert::precondition( !$cirrusDebugOptions->isCirrusDumpQuery(), 'Must not reach this method when dumping the query' );
      Severity: Major
      Found in includes/Searcher.php - About 5 hrs to fix

        Method build has 123 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function build() {
                $resultsType = $this->searchContext->getResultsType();
        
                $query = new Query();
                $query->setTrackTotalHits( $this->searchContext->getTrackTotalHits() );
        Severity: Major
        Found in includes/Search/SearchRequestBuilder.php - About 4 hrs to fix

          Function postProcess has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
          Open

              public function postProcess( CompletionResultsCollector $collector, ResultSet $results, $indexName ) {
                  $suggestResp = $results->getSuggests();
                  if ( $suggestResp === [] ) {
                      // Edge case where the index contains 0 documents and does not even return the 'suggest' field
                      return 0;
          Severity: Minor
          Found in includes/Query/CompSuggestQueryBuilder.php - About 4 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 sendData has 120 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function sendData( $indexSuffix, array $documents ) {
                  if ( !$documents ) {
                      return Status::newGood();
                  }
          
          
          Severity: Major
          Found in includes/DataSender.php - About 4 hrs to fix

            File CirrusSearch.php has 366 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            <?php
            
            namespace CirrusSearch;
            
            use CirrusSearch\Extra\MultiList\MultiListBuilder;
            Severity: Minor
            Found in includes/CirrusSearch.php - About 4 hrs to fix

              Function buildCirrusSearchRequestEvent has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function buildCirrusSearchRequestEvent() {
                      global $wgRequest, $wgServerName;
                      $webrequest = $wgRequest;
              
                      // for the moment RequestLog::getRequests() is still created in the
              Severity: Minor
              Found in includes/RequestLogger.php - About 4 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 replace has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function replace( array $profile, array $replacement ) {
                      $cur = &$profile;
                      foreach ( $replacement['matches'] as $match ) {
                          if ( !is_array( $cur ) ) {
                              return $profile;
              Severity: Minor
              Found in includes/Profile/ArrayPathSetter.php - About 4 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 sendData has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function sendData( $indexSuffix, array $documents ) {
                      if ( !$documents ) {
                          return Status::newGood();
                      }
              
              
              Severity: Minor
              Found in includes/DataSender.php - About 4 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

              AnalyzerBuilder has 34 functions (exceeds 20 allowed). Consider refactoring.
              Open

              class AnalyzerBuilder {
                  /**
                   * Indicate that filters should be automatically appended or prepended, rather
                   * than inserted before a given filter.
                   */
              Severity: Minor
              Found in includes/Maintenance/AnalyzerBuilder.php - About 4 hrs to fix

                Method getDefaultFields has 108 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function getDefaultFields() {
                        // Note never to set something as type='object' here because that isn't returned by elasticsearch
                        // and is inferred anyway.
                        $titleExtraAnalyzers = [
                            [ 'analyzer' => 'prefix', 'search_analyzer' => 'near_match', 'index_options' => 'docs', 'norms' => false ],
                Severity: Major
                Found in includes/Maintenance/MappingConfigBuilder.php - About 4 hrs to fix

                  File FullTextQueryStringQueryBuilder.php has 344 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  <?php
                  
                  namespace CirrusSearch\Query;
                  
                  use CirrusSearch\Extra\Query\TokenCountRouter;
                  Severity: Minor
                  Found in includes/Query/FullTextQueryStringQueryBuilder.php - About 4 hrs to fix

                    Function readLineBatch has a Cognitive Complexity of 29 (exceeds 5 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 4 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

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

                    class Searcher extends ElasticsearchIntermediary implements SearcherFactory {
                        public const SUGGESTION_HIGHLIGHT_PRE = '<em>';
                        public const SUGGESTION_HIGHLIGHT_POST = '</em>';
                        public const HIGHLIGHT_PRE_MARKER = ''; // \uE000. Can't be a unicode literal until php7
                        public const HIGHLIGHT_PRE = '<span class="searchmatch">';
                    Severity: Minor
                    Found in includes/Searcher.php - About 4 hrs to fix

                      File Reindexer.php has 338 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      <?php
                      
                      namespace CirrusSearch\Maintenance;
                      
                      use CirrusSearch\Connection;
                      Severity: Minor
                      Found in includes/Maintenance/Reindexer.php - About 4 hrs to fix

                        Function build has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function build() {
                                $resultsType = $this->searchContext->getResultsType();
                        
                                $query = new Query();
                                $query->setTrackTotalHits( $this->searchContext->getTrackTotalHits() );
                        Severity: Minor
                        Found in includes/Search/SearchRequestBuilder.php - About 4 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 execute has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function execute() {
                                $this->disablePoolCountersAndLogging();
                                $wiki = sprintf( "[%20s]", WikiMap::getCurrentWikiId() );
                        
                                // Make sure we've actually got indices to populate
                        Severity: Minor
                        Found in maintenance/ForceSearchIndex.php - About 4 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