wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub
includes/Searcher.php

Summary

Maintainability
F
5 days
Test Coverage

File Searcher.php has 676 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace CirrusSearch;

use CirrusSearch\Fallbacks\FallbackRunner;
Severity: Major
Found in includes/Searcher.php - About 1 day 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 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

      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

        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

        Method searchTextInternal has 64 lines of code (exceeds 25 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: Major
        Found in includes/Searcher.php - About 2 hrs 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 __construct has 12 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                    Connection $conn, $offset,
                    $limit,
                    SearchConfig $config,
                    array $namespaces = null,
                    User $user = null,
            Severity: Major
            Found in includes/Searcher.php - About 1 hr to fix

              Method searchArchive has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function searchArchive( $term ) {
                      $this->searchContext->setOriginalSearchTerm( $term );
                      $term = $this->searchContext->escaper()->fixupWholeQueryString( $term );
                      $this->setResultsType( new TitleResultsType() );
              
              
              Severity: Minor
              Found in includes/Searcher.php - About 1 hr to fix

                Function get has a Cognitive Complexity of 10 (exceeds 5 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

                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 buildFullTextSearch has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function buildFullTextSearch( $term ) {
                        // Convert the unicode character 'ideographic whitespace' into standard
                        // whitespace. Cirrussearch treats them both as normal whitespace, but
                        // the preceding isn't appropriately trimmed.
                        // No searching for nothing! That takes forever!
                Severity: Minor
                Found in includes/Searcher.php - About 35 mins 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

                Avoid too many return statements within this method.
                Open

                            return $msearches->failure( Status::newFatal( 'cirrussearch-backend-error' ) );
                Severity: Major
                Found in includes/Searcher.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return $msearches->failure( $status );
                  Severity: Major
                  Found in includes/Searcher.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return $mresults->transformAndGetSingle( $this->searchContext->getResultsType(), self::MAINSEARCH_MSEARCH_KEY );
                    Severity: Major
                    Found in includes/Searcher.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return $status;
                      Severity: Major
                      Found in includes/Searcher.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return $work();
                        Severity: Major
                        Found in includes/Searcher.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return $mreponses;
                          Severity: Major
                          Found in includes/Searcher.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return $responses->dumpResults( $description );
                            Severity: Major
                            Found in includes/Searcher.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return $status;
                              Severity: Major
                              Found in includes/Searcher.php - About 30 mins to fix

                                Function getPoolCounterType has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    private function getPoolCounterType(): string {
                                        // Default pool counter for all search requests. Note that not all
                                        // possible requests go through Searcher, so this isn't globally
                                        // definitive.
                                        $pool = 'CirrusSearch-Search';
                                Severity: Minor
                                Found in includes/Searcher.php - About 25 mins 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

                                There are no issues that match your filters.

                                Category
                                Status