wikimedia/mediawiki-core

View on GitHub
includes/search/SearchEngine.php

Summary

Maintainability
D
3 days
Test Coverage

SearchEngine has 44 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class SearchEngine {
    public const DEFAULT_SORT = 'relevance';

    /** @var string */
    public $prefix = '';
Severity: Minor
Found in includes/search/SearchEngine.php - About 6 hrs to fix

    File SearchEngine.php has 394 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /**
     * Basic search engine
     *
     * This program is free software; you can redistribute it and/or modify
    Severity: Minor
    Found in includes/search/SearchEngine.php - About 5 hrs to fix

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

          public static function parseNamespacePrefixes(
              $query,
              $withAllKeyword = true,
              $withPrefixSearchExtractNamespaceHook = false
          ) {
      Severity: Minor
      Found in includes/search/SearchEngine.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 getSearchIndexFields has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getSearchIndexFields() {
              $models = MediaWikiServices::getInstance()->getContentHandlerFactory()->getContentModels();
              $fields = [];
              $seenHandlers = new SplObjectStorage();
              foreach ( $models as $model ) {
      Severity: Minor
      Found in includes/search/SearchEngine.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 parseNamespacePrefixes has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function parseNamespacePrefixes(
              $query,
              $withAllKeyword = true,
              $withPrefixSearchExtractNamespaceHook = false
          ) {
      Severity: Minor
      Found in includes/search/SearchEngine.php - About 1 hr to fix

        Method processCompletionResults has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function processCompletionResults( $search, SearchSuggestionSet $suggestions ) {
                // We over-fetched to determine pagination. Shrink back down if we have extra results
                // and mark if pagination is possible
                $suggestions->shrink( $this->limit );
        
        
        Severity: Minor
        Found in includes/search/SearchEngine.php - About 1 hr to fix

          Function processCompletionResults has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function processCompletionResults( $search, SearchSuggestionSet $suggestions ) {
                  // We over-fetched to determine pagination. Shrink back down if we have extra results
                  // and mark if pagination is possible
                  $suggestions->shrink( $this->limit );
          
          
          Severity: Minor
          Found in includes/search/SearchEngine.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 getSearchIndexFields has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getSearchIndexFields() {
                  $models = MediaWikiServices::getInstance()->getContentHandlerFactory()->getContentModels();
                  $fields = [];
                  $seenHandlers = new SplObjectStorage();
                  foreach ( $models as $model ) {
          Severity: Minor
          Found in includes/search/SearchEngine.php - About 1 hr to fix

            Function augmentSearchResults has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                public function augmentSearchResults( ISearchResultSet $resultSet ) {
                    $setAugmentors = [];
                    $rowAugmentors = [];
                    $this->getHookRunner()->onSearchResultsAugment( $setAugmentors, $rowAugmentors );
                    if ( !$setAugmentors && !$rowAugmentors ) {
            Severity: Minor
            Found in includes/search/SearchEngine.php - About 45 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

            Function completionSearchWithVariants has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                public function completionSearchWithVariants( $search ) {
                    if ( trim( $search ) === '' ) {
                        return SearchSuggestionSet::emptySuggestionSet(); // Return empty result
                    }
                    $search = $this->normalizeNamespaces( $search );
            Severity: Minor
            Found in includes/search/SearchEngine.php - About 45 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

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

                private function maybePaginate( Closure $fn ) {
                    if ( $this instanceof PaginatingSearchEngine ) {
                        return $fn();
                    }
                    $this->limit++;
            Severity: Minor
            Found in includes/search/SearchEngine.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