wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub
includes/Parser/QueryStringRegex/QueryStringRegexParser.php

Summary

Maintainability
F
3 days
Test Coverage

File QueryStringRegexParser.php has 507 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace CirrusSearch\Parser\QueryStringRegex;

use CirrusSearch\Parser\AST\BooleanClause;
Severity: Major
Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.php - About 1 day to fix

    Function expression has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

        private function expression() {
            $clauses = [];
            $left = null;
            // Last boolean operator seen, -1 means none
            $lastBoolType = -1;
    Severity: Minor
    Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.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 expression has 94 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function expression() {
            $clauses = [];
            $left = null;
            // Last boolean operator seen, -1 means none
            $lastBoolType = -1;
    Severity: Major
    Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.php - About 3 hrs to fix

      QueryStringRegexParser has 27 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class QueryStringRegexParser implements QueryParser {
          /**
           * Whitespace regex including unicode and some control chars
           */
          private const WHITESPACE_REGEX = '/\G[\pZ\pC]+/u';
      Severity: Minor
      Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.php - About 3 hrs 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 nextToken has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function nextToken() {
                  Assert::precondition( $this->token->getStart() < $this->offset,
                      'You should not call nextToken() twice on the same offsets' );
                  $this->token->copyTo( $this->lookBehind );
                  $this->token->reset();
          Severity: Minor
          Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.php - About 1 hr to fix

            Function parse has a Cognitive Complexity of 9 (exceeds 5 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 55 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 checkQueryLen has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                private function checkQueryLen(): void {
                    Assert::precondition( $this->query !== null, "Query must be set" );
                    $maxLen = $this->maxQueryLen;
                    $exemptKeywords = [];
                    foreach ( $this->preTaggedNodes as $node ) {
            Severity: Minor
            Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.php - About 55 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 __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                    \CirrusSearch\Parser\KeywordRegistry $keywordRegistry,
                    Escaper $escaper,
                    $qmarkStripLevel,
                    ParsedQueryClassifiersRepository $classifierRepository,
                    NamespacePrefixParser $namespacePrefixParser,
            Severity: Minor
            Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.php - About 45 mins to fix

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

                  private function nextToken() {
                      Assert::precondition( $this->token->getStart() < $this->offset,
                          'You should not call nextToken() twice on the same offsets' );
                      $this->token->copyTo( $this->lookBehind );
                      $this->token->reset();
              Severity: Minor
              Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.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 true;
              Severity: Major
              Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return true;
                Severity: Major
                Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.php - About 30 mins to fix

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

                      private function cleanup() {
                          $query = $this->rawQuery;
                          $nquery = Util::stripQuestionMarks( $query, $this->questionMarkStripLevel );
                          if ( $nquery !== $query ) {
                              $this->queryCleanups[ParsedQuery::CLEANUP_QMARK_STRIPPING] = true;
                  Severity: Minor
                  Found in includes/Parser/QueryStringRegex/QueryStringRegexParser.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