gdbots/query-parser-php

View on GitHub
src/Builder/ElasticaQueryBuilder.php

Summary

Maintainability
D
2 days
Test Coverage

File ElasticaQueryBuilder.php has 356 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
declare(strict_types=1);

namespace Gdbots\QueryParser\Builder;

Severity: Minor
Found in src/Builder/ElasticaQueryBuilder.php - About 4 hrs to fix

    The class ElasticaQueryBuilder has an overall complexity of 84 which is very high. The configured complexity threshold is 50.
    Open

    class ElasticaQueryBuilder extends AbstractQueryBuilder
    {
        /** @var RuflinQueryBuilder */
        protected $qb;
    
    
    Severity: Minor
    Found in src/Builder/ElasticaQueryBuilder.php by phpmd

    Since: PHPMD 0.2.5

    The Weighted Method Count (WMC) of a class is a good indicator of how much time and effort is required to modify and maintain this class. The WMC metric is defined as the sum of complexities of all methods declared in a class. A large number of methods also means that this class has a greater potential impact on derived classes.

    Example:

    class Foo {
          public function bar() {
              if ($a == $b)  {
                  if ($a1 == $b1) {
                      fiddle();
                  } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                  }
              }
          }
          public function baz() {
              if ($a == $b) {
                  if ($a1 == $b1) {
                      fiddle();
                  } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                  }
              }
          }
          // Several other complex methods
      }

    Source: http://phpmd.org/rules/codesize.txt

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

        protected function handleRange(Range $range, Field $field, bool $cacheable = false): void
        {
            $useBoost = $field->useBoost();
            $boost = $field->getBoost();
            $boolOp = $field->getBoolOperator();
    Severity: Minor
    Found in src/Builder/ElasticaQueryBuilder.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

    ElasticaQueryBuilder has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ElasticaQueryBuilder extends AbstractQueryBuilder
    {
        /** @var RuflinQueryBuilder */
        protected $qb;
    
    
    Severity: Minor
    Found in src/Builder/ElasticaQueryBuilder.php - About 2 hrs to fix

      Function addTextToQuery has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function addTextToQuery(string $method, Node $node, ?Field $field = null): void
          {
              if ($node instanceof Word && $node->isStopWord() && $this->ignoreStopWords) {
                  return;
              }
      Severity: Minor
      Found in src/Builder/ElasticaQueryBuilder.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 addTextToQuery has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function addTextToQuery(string $method, Node $node, ?Field $field = null): void
          {
              if ($node instanceof Word && $node->isStopWord() && $this->ignoreStopWords) {
                  return;
              }
      Severity: Major
      Found in src/Builder/ElasticaQueryBuilder.php - About 2 hrs to fix

        Function addTermToQuery has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function addTermToQuery(string $method, Node $node, ?Field $field = null, bool $cacheable = false): void
            {
                if ($node instanceof Emoji && $this->ignoreEmojis) {
                    return;
                }
        Severity: Minor
        Found in src/Builder/ElasticaQueryBuilder.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 handleRange has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function handleRange(Range $range, Field $field, bool $cacheable = false): void
            {
                $useBoost = $field->useBoost();
                $boost = $field->getBoost();
                $boolOp = $field->getBoolOperator();
        Severity: Minor
        Found in src/Builder/ElasticaQueryBuilder.php - About 2 hrs to fix

          Method addTermToQuery has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function addTermToQuery(string $method, Node $node, ?Field $field = null, bool $cacheable = false): void
              {
                  if ($node instanceof Emoji && $this->ignoreEmojis) {
                      return;
                  }
          Severity: Minor
          Found in src/Builder/ElasticaQueryBuilder.php - About 1 hr to fix

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

                protected function endSubquery(Subquery $subquery, ?Field $field = null): void
                {
                    $params = $this->boolQuery->getParams();
                    if (!empty($params)) {
                        $this->boolQuery->setMinimumShouldMatch(1);
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.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

            The method addTermToQuery() has an NPath complexity of 2592. The configured NPath complexity threshold is 200.
            Open

                protected function addTermToQuery(string $method, Node $node, ?Field $field = null, bool $cacheable = false): void
                {
                    if ($node instanceof Emoji && $this->ignoreEmojis) {
                        return;
                    }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example:

            class Foo {
                  function bar() {
                      // lots of complicated code
                  }
              }

            Source: http://phpmd.org/rules/codesize.txt

            The method addTextToQuery() has an NPath complexity of 1440. The configured NPath complexity threshold is 200.
            Open

                protected function addTextToQuery(string $method, Node $node, ?Field $field = null): void
                {
                    if ($node instanceof Word && $node->isStopWord() && $this->ignoreStopWords) {
                        return;
                    }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example:

            class Foo {
                  function bar() {
                      // lots of complicated code
                  }
              }

            Source: http://phpmd.org/rules/codesize.txt

            The method handleRange() has an NPath complexity of 288. The configured NPath complexity threshold is 200.
            Open

                protected function handleRange(Range $range, Field $field, bool $cacheable = false): void
                {
                    $useBoost = $field->useBoost();
                    $boost = $field->getBoost();
                    $boolOp = $field->getBoolOperator();
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example:

            class Foo {
                  function bar() {
                      // lots of complicated code
                  }
              }

            Source: http://phpmd.org/rules/codesize.txt

            The method handleRange() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
            Open

                protected function handleRange(Range $range, Field $field, bool $cacheable = false): void
                {
                    $useBoost = $field->useBoost();
                    $boost = $field->getBoost();
                    $boolOp = $field->getBoolOperator();
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example:

            // Cyclomatic Complexity = 11
              class Foo {
              1   public function example() {
              2       if ($a == $b) {
              3           if ($a1 == $b1) {
                              fiddle();
              4           } elseif ($a2 == $b2) {
                              fiddle();
                          } else {
                              fiddle();
                          }
              5       } elseif ($c == $d) {
              6           while ($c == $d) {
                              fiddle();
                          }
              7        } elseif ($e == $f) {
              8           for ($n = 0; $n < $h; $n++) {
                              fiddle();
                          }
                      } else {
                          switch ($z) {
              9               case 1:
                                  fiddle();
                                  break;
              10              case 2:
                                  fiddle();
                                  break;
              11              case 3:
                                  fiddle();
                                  break;
                              default:
                                  fiddle();
                                  break;
                          }
                      }
                  }
              }

            Source: http://phpmd.org/rules/codesize.txt

            The method addTermToQuery() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10.
            Open

                protected function addTermToQuery(string $method, Node $node, ?Field $field = null, bool $cacheable = false): void
                {
                    if ($node instanceof Emoji && $this->ignoreEmojis) {
                        return;
                    }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example:

            // Cyclomatic Complexity = 11
              class Foo {
              1   public function example() {
              2       if ($a == $b) {
              3           if ($a1 == $b1) {
                              fiddle();
              4           } elseif ($a2 == $b2) {
                              fiddle();
                          } else {
                              fiddle();
                          }
              5       } elseif ($c == $d) {
              6           while ($c == $d) {
                              fiddle();
                          }
              7        } elseif ($e == $f) {
              8           for ($n = 0; $n < $h; $n++) {
                              fiddle();
                          }
                      } else {
                          switch ($z) {
              9               case 1:
                                  fiddle();
                                  break;
              10              case 2:
                                  fiddle();
                                  break;
              11              case 3:
                                  fiddle();
                                  break;
                              default:
                                  fiddle();
                                  break;
                          }
                      }
                  }
              }

            Source: http://phpmd.org/rules/codesize.txt

            The method addTextToQuery() has a Cyclomatic Complexity of 21. The configured cyclomatic complexity threshold is 10.
            Open

                protected function addTextToQuery(string $method, Node $node, ?Field $field = null): void
                {
                    if ($node instanceof Word && $node->isStopWord() && $this->ignoreStopWords) {
                        return;
                    }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example:

            // Cyclomatic Complexity = 11
              class Foo {
              1   public function example() {
              2       if ($a == $b) {
              3           if ($a1 == $b1) {
                              fiddle();
              4           } elseif ($a2 == $b2) {
                              fiddle();
                          } else {
                              fiddle();
                          }
              5       } elseif ($c == $d) {
              6           while ($c == $d) {
                              fiddle();
                          }
              7        } elseif ($e == $f) {
              8           for ($n = 0; $n < $h; $n++) {
                              fiddle();
                          }
                      } else {
                          switch ($z) {
              9               case 1:
                                  fiddle();
                                  break;
              10              case 2:
                                  fiddle();
                                  break;
              11              case 3:
                                  fiddle();
                                  break;
                              default:
                                  fiddle();
                                  break;
                          }
                      }
                  }
              }

            Source: http://phpmd.org/rules/codesize.txt

            The class ElasticaQueryBuilder has a coupling between objects value of 21. Consider to reduce the number of dependencies under 13.
            Open

            class ElasticaQueryBuilder extends AbstractQueryBuilder
            {
                /** @var RuflinQueryBuilder */
                protected $qb;
            
            
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.1.0

            A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

            Example:

            class Foo {
                  /**
                   * @var \foo\bar\X
                   */
                  private $x = null;
            
                  /**
                   * @var \foo\bar\Y
                   */
                  private $y = null;
            
                  /**
                   * @var \foo\bar\Z
                   */
                  private $z = null;
            
                  public function setFoo(\Foo $foo) {}
                  public function setBar(\Bar $bar) {}
                  public function setBaz(\Baz $baz) {}
            
                  /**
                   * @return \SplObjectStorage
                   * @throws \OutOfRangeException
                   * @throws \InvalidArgumentException
                   * @throws \ErrorException
                   */
                  public function process(\Iterator $it) {}
            
                  // ...
              }

            Source: http://phpmd.org/rules/design.txt

            The method mustNotMatchTerm has a boolean flag argument $cacheable, which is a certain sign of a Single Responsibility Principle violation.
            Open

                protected function mustNotMatchTerm(Node $node, ?Field $field = null, bool $cacheable = false): void
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example:

            class Foo {
                  public function bar($flag = true) {
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method createDateRangeForSingleNode has a boolean flag argument $cacheable, which is a certain sign of a Single Responsibility Principle violation.
            Open

                    bool $cacheable = false,
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example:

            class Foo {
                  public function bar($flag = true) {
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method ignoreEmoticons has a boolean flag argument $ignoreEmoticons, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function ignoreEmoticons(bool $ignoreEmoticons = true): self
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example:

            class Foo {
                  public function bar($flag = true) {
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method ignoreStopWords has a boolean flag argument $ignoreStopWords, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function ignoreStopWords(bool $ignoreStopWords = true): self
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example:

            class Foo {
                  public function bar($flag = true) {
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method mustMatchTerm has a boolean flag argument $cacheable, which is a certain sign of a Single Responsibility Principle violation.
            Open

                protected function mustMatchTerm(Node $node, ?Field $field = null, bool $cacheable = false): void
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example:

            class Foo {
                  public function bar($flag = true) {
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method addTermToQuery has a boolean flag argument $cacheable, which is a certain sign of a Single Responsibility Principle violation.
            Open

                protected function addTermToQuery(string $method, Node $node, ?Field $field = null, bool $cacheable = false): void
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example:

            class Foo {
                  public function bar($flag = true) {
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method handleRange has a boolean flag argument $cacheable, which is a certain sign of a Single Responsibility Principle violation.
            Open

                protected function handleRange(Range $range, Field $field, bool $cacheable = false): void
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example:

            class Foo {
                  public function bar($flag = true) {
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method lowerCaseTerms has a boolean flag argument $lowerCaseTerms, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function lowerCaseTerms(bool $lowerCaseTerms = true): self
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example:

            class Foo {
                  public function bar($flag = true) {
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method ignoreEmojis has a boolean flag argument $ignoreEmojis, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function ignoreEmojis(bool $ignoreEmojis = true): self
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example:

            class Foo {
                  public function bar($flag = true) {
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method addTermToQuery uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                    } else {
                        $useBoost = $node->useBoost();
                        $boost = $node->getBoost();
                    }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method handleRange uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                        } else {
                            $this->addToBoolQuery('addFilter', $field->getName(), $this->qb->query()->range($field->getName(), $data));
                        }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method addTermToQuery uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                    } else {
                        $term = $this->qb->query()->term();
                        $term->setTerm($fieldName, $value, $boost);
                    }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method addTermToQuery uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                        } else {
                            $this->addToBoolQuery('addFilter', $fieldName, $term);
                        }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method endSubquery uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                        } else {
                            $useBoost = $subquery->useBoost();
                            $boost = $subquery->getBoost();
                            $boolOp = $subquery->getBoolOperator();
                        }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            Avoid using static access to class '\Gdbots\QueryParser\Enum\BoolOperator' in method 'endSubquery'.
            Open

                        if ($boolOp->equals(BoolOperator::REQUIRED())) {
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example:

            class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            Avoid using static access to class '\Gdbots\QueryParser\Enum\BoolOperator' in method 'endSubquery'.
            Open

                        } elseif ($boolOp->equals(BoolOperator::PROHIBITED())) {
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example:

            class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method createDateRangeForSingleNode uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                    } else {
                        $data = [$operator => $node->toDateTime($this->localTimeZone)->format('Y-m-d')];
                    }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method addTermToQuery uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                    } else {
                        $this->addToBoolQuery($method, $fieldName, $term);
                    }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method addTextToQuery uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                    } else {
                        $data = ['query' => $node->getValue(), 'operator' => 'and', 'lenient' => true];
            
                        if ($useBoost) {
                            $data['boost'] = $boost;
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method endSubquery uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                        } else {
                            $this->outerBoolQuery->addShould($this->boolQuery);
                        }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            Avoid using static access to class '\Gdbots\QueryParser\Enum\BoolOperator' in method 'handleRange'.
            Open

                    if ($boolOp->equals(BoolOperator::REQUIRED())) {
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example:

            class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method addTextToQuery uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                    } else {
                        $useBoost = $node->useBoost();
                        $boost = $node->getBoost();
                        $useFuzzy = $node->useFuzzy();
                        $fuzzy = $node->getFuzzy();
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            Avoid using static access to class '\Gdbots\QueryParser\Enum\BoolOperator' in method 'handleRange'.
            Open

                    } elseif ($boolOp->equals(BoolOperator::PROHIBITED())) {
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example:

            class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method handleRange uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                    } else {
                        if ($range->hasLowerNode()) {
                            $data[$lowerOperator] = $range->getLowerNode()->getValue();
                        }
                        if ($range->hasUpperNode()) {
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method handleRange uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                    } else {
                        $method = 'addShould';
                    }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            The method handleRange uses an else expression. Else is never necessary and you can simplify the code to work without else.
            Open

                    } else {
                        $lowerOperator = 'gte';
                        $upperOperator = 'lte';
                    }
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 1.4.0

            An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example:

            class Foo
              {
                  public function bar($flag)
                  {
                      if ($flag) {
                          // one branch
                      } else {
                          // another branch
                      }
                  }
              }

            Source: http://phpmd.org/rules/cleancode.txt

            Avoid variables with short names like $qb. Configured minimum length is 3.
            Open

                protected $qb;
            Severity: Minor
            Found in src/Builder/ElasticaQueryBuilder.php by phpmd

            Since: PHPMD 0.2

            Detects when a field, local, or parameter has a very short name.

            Example:

            class Something {
                  private $q = 15; // VIOLATION - Field
                  public static function main( array $as ) { // VIOLATION - Formal
                      $r = 20 + $this->q; // VIOLATION - Local
                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                          $r += $this->q;
                      }
                  }
              }

            Source: http://phpmd.org/rules/naming.txt

            Line exceeds 120 characters; contains 123 characters
            Open

                            $this->addToBoolQuery('addFilter', $field->getName(), $this->qb->query()->range($field->getName(), $data));

            Line exceeds 120 characters; contains 126 characters
            Open

                    $value = $this->lowerCaseTerms && !$node instanceof Numbr ? strtolower((string)$node->getValue()) : $node->getValue();

            There are no issues that match your filters.

            Category
            Status