wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub
includes/Util.php

Summary

Maintainability
D
1 day
Test Coverage

File Util.php has 318 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace CirrusSearch;

use MediaWiki\Context\RequestContext;
Severity: Minor
Found in includes/Util.php - About 3 hrs to fix

    Util has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Util {
        /**
         * Cache getDefaultBoostTemplates()
         *
         * @var array|null boost templates
    Severity: Minor
    Found in includes/Util.php - About 2 hrs to fix

      Method identifyNamespace has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function identifyNamespace( $namespace, $method = 'naive', Language $language = null ) {
              static $naive = null;
              static $utr30 = null;
      
              $normalizer = null;
      Severity: Minor
      Found in includes/Util.php - About 1 hr to fix

        Function identifyNamespace has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function identifyNamespace( $namespace, $method = 'naive', Language $language = null ) {
                static $naive = null;
                static $utr30 = null;
        
                $normalizer = null;
        Severity: Minor
        Found in includes/Util.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 getOnWikiBoostTemplates has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static function getOnWikiBoostTemplates( SearchConfig $config ) {
                $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $cacheKey = $cache->makeGlobalKey( 'cirrussearch-boost-templates', $config->getWikiId() );
                if ( $config->getWikiId() == WikiMap::getCurrentWikiId() ) {
                    // Local wiki we can fetch boost templates from system
        Severity: Minor
        Found in includes/Util.php - About 1 hr to fix

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

              public static function looksLikeAutomation( SearchConfig $config, string $ip, array $headers ): bool {
                  // Is there an http header that can be matched with regex to flag automation,
                  // such as the user-agent or a flag applied by some infrastructure?
                  $automationHeaders = $config->get( 'CirrusSearchAutomationHeaderRegexes' ) ?? [];
                  foreach ( $automationHeaders as $name => $pattern ) {
          Severity: Minor
          Found in includes/Util.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

          Method setIfDefined has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  array $sourceArray,
                  $sourceKey,
                  array &$destArray,
                  $destKey = null,
                  $mapFn = null,
          Severity: Minor
          Found in includes/Util.php - About 45 mins to fix

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

                public static function processSearchRawReturn( $result, WebRequest $request,
                                                               CirrusDebugOptions $debugOptions ) {
                    $output = null;
                    $header = null;
                    if ( $debugOptions->getCirrusExplainFormat() !== null ) {
            Severity: Minor
            Found in includes/Util.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

            Method overrideNumeric has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                public static function overrideNumeric( &$dest, $request, $name, $limit = null, $upperLimit = true ) {
            Severity: Minor
            Found in includes/Util.php - About 35 mins to fix

              Function overrideNumeric has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function overrideNumeric( &$dest, $request, $name, $limit = null, $upperLimit = true ) {
                      $val = $request->getVal( $name );
                      if ( $val !== null && is_numeric( $val ) ) {
                          if ( $limit === null ) {
                              $dest = $val;
              Severity: Minor
              Found in includes/Util.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 $nonLocalCache;
              Severity: Major
              Found in includes/Util.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return [];
                Severity: Major
                Found in includes/Util.php - About 30 mins to fix

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

                      public static function stripQuestionMarks( $term, $strippingLevel ) {
                          if ( strpos( $term, 'insource:/' ) === false &&
                               strpos( $term, 'intitle:/' ) === false &&
                              !preg_match( '/^[\p{P}\p{Z}]+$/u', $term )
                          ) {
                  Severity: Minor
                  Found in includes/Util.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

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

                      public static function setIfDefined(
                          array $sourceArray,
                          $sourceKey,
                          array &$destArray,
                          $destKey = null,
                  Severity: Minor
                  Found in includes/Util.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

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

                      public static function isEmpty( $v ) {
                          return ( is_array( $v ) && count( $v ) === 0 ) ||
                              ( is_object( $v ) && count( (array)$v ) === 0 ) ||
                              ( is_string( $v ) && strlen( $v ) === 0 ) ||
                              ( $v === null );
                  Severity: Minor
                  Found in includes/Util.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