Asymptix/Framework

View on GitHub
framework/db/DBPreparedQuery.php

Summary

Maintainability
C
1 day
Test Coverage

Function checkParameterTypes has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    private static function checkParameterTypes($params, $types) {
        if (count($params) != strlen($types)) {
            throw new DBCoreException(
                "Number of types is not equal parameters number"
            );
Severity: Minor
Found in framework/db/DBPreparedQuery.php - About 3 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

The class DBPreparedQuery has 13 public methods. Consider refactoring DBPreparedQuery to keep number of public methods under 10.
Open

class DBPreparedQuery extends DBQuery {

    /**
     * DB query template.
     *
Severity: Minor
Found in framework/db/DBPreparedQuery.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

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

class DBPreparedQuery extends DBQuery {

    /**
     * DB query template.
     *
Severity: Minor
Found in framework/db/DBPreparedQuery.php by phpmd

Method checkParameterTypes has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private static function checkParameterTypes($params, $types) {
        if (count($params) != strlen($types)) {
            throw new DBCoreException(
                "Number of types is not equal parameters number"
            );
Severity: Major
Found in framework/db/DBPreparedQuery.php - About 2 hrs to fix

    Function sqlPushValues has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        public function sqlPushValues($values, $separator = ", ") {
            $chunks = [];
            foreach ($values as $fieldName => $fieldValue) {
                if (!is_array($fieldValue)) {
                    if (!is_null($fieldValue)) {
    Severity: Minor
    Found in framework/db/DBPreparedQuery.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 prepareLimit has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function prepareLimit() {
            $count = null;
            if (!is_null($this->limit)) {
                if (Tools::isInteger($this->limit)) {
                    $this->query.= " LIMIT " . $this->limit;
    Severity: Minor
    Found in framework/db/DBPreparedQuery.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 prepare has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        public function prepare($query, $conditions = null, $order = null, $offset = null, $count = null) {
            if (empty($query)) {
                throw new DBCoreException("Nothing to run, SQL query is not initialized");
            }
            $this->query = $query;
    Severity: Minor
    Found in framework/db/DBPreparedQuery.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 sqlTypesString has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function sqlTypesString($fieldsList, $idFieldName = "") {
            $typesString = "";
            foreach ($fieldsList as $fieldName => $fieldValue) {
                if ($fieldName != $idFieldName) {
                    if (Tools::isDouble($fieldValue)) {
    Severity: Minor
    Found in framework/db/DBPreparedQuery.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 prepare has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        public function prepare($query, $conditions = null, $order = null, $offset = null, $count = null) {
    Severity: Minor
    Found in framework/db/DBPreparedQuery.php - About 35 mins to fix

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

          public function prepareOrder() {
              if (!empty($this->order)) {
                  $this->query.= " ORDER BY";
                  if (is_array($this->order)) {
                      foreach ($this->order as $fieldName => $ord) {
      Severity: Minor
      Found in framework/db/DBPreparedQuery.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

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

          private static function checkParameterTypes($params, $types) {
              if (count($params) != strlen($types)) {
                  throw new DBCoreException(
                      "Number of types is not equal parameters number"
                  );
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      CyclomaticComplexity

      Since: 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 https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

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

          public function go($debug = false) {
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      BooleanArgumentFlag

      Since: 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 https://phpmd.org/rules/cleancode.html#booleanargumentflag

      Avoid using static access to class 'Asymptix\db\DBField' in method 'sqlPushValues'.
      Open

                          $this->types.= DBField::getType($param);
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Asymptix\core\Tools' in method 'prepareLimit'.
      Open

                  if (Tools::isInteger($this->limit)) {
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Asymptix\core\Tools' in method 'prepareLimit'.
      Open

                      if (Tools::isInteger($offset) && Tools::isInteger($count)) {
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Asymptix\core\Tools' in method 'prepareLimit'.
      Open

                      if (Tools::isInteger($offset) && Tools::isInteger($count)) {
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Asymptix\core\Tools' in method 'sqlTypesString'.
      Open

                      if (Tools::isDouble($fieldValue)) {
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class 'Asymptix\db\DBField' in method 'checkParameterTypes'.
      Open

                  $typeByValue = DBField::getType($value);
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Asymptix\core\Tools' in method 'sqlTypesString'.
      Open

                      } elseif (Tools::isInteger($fieldValue)) {
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class 'Asymptix\db\DBField' in method 'sqlPushValues'.
      Open

                          $this->types.= DBField::getType($fieldValue);
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      The method sqlPushValues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                      } else {
                          $chunks[] = $fieldName;
                      }
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

      Avoid using static access to class 'Asymptix\db\DBCore' in method 'go'.
      Open

                  return DBCore::doUpdateQuery($this);
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      The method checkParameterTypes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else { // in case if we try send non-string parameters as a string value
                      switch ($type) {
                          case 'i':
                              if (!(Tools::isNumeric($value) && ((string)(int)$value === $value))) {
                                  throw new DBCoreException(
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

      The method go uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  if ($this->isSelector()) {
                      return DBCore::doSelectQuery($this);
                  }
      
      
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

      Avoid using static access to class 'Asymptix\db\DBCore' in method 'go'.
      Open

                      return DBCore::doSelectQuery($this);
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Asymptix\core\Tools' in method 'checkParameterTypes'.
      Open

                              if (!Tools::isDoubleString($value)) {
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      The method prepareLimit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      throw new DBCoreException("Invalid LIMIT param in select() method.");
                  }
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

      The method sqlTypesString uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                      } else {
                          $typesString.= "s";
                      }
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

      The method prepare uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $this->dbQuery->limit = [$offset, $count];
                  }
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

      Avoid using static access to class 'Asymptix\db\DBField' in method 'sqlSingleTypeString'.
      Open

              $type = DBField::castType($type);
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Asymptix\core\Tools' in method 'checkParameterTypes'.
      Open

                              if (!(Tools::isNumeric($value) && ((string)(int)$value === $value))) {
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      StaticAccess

      Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

      The method prepareLimit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                      } else {
                          throw new DBCoreException("Invalid LIMIT param in select() method.");
                      }
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

      The method sqlPushValues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $condition = $fieldName;
                      $localParams = $fieldValue;
      
                      $chunks[] = $condition;
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

      Avoid using short method names like DBPreparedQuery::go(). The configured minimum method name length is 3.
      Open

          public function go($debug = false) {
              if ($debug) {
                  $this->debug();
              } else {
                  if ($this->isSelector()) {
      Severity: Minor
      Found in framework/db/DBPreparedQuery.php by phpmd

      ShortMethodName

      Since: 0.2

      Detects when very short method names are used.

      Example

      class ShortMethod {
          public function a( $index ) { // Violation
          }
      }

      Source https://phpmd.org/rules/naming.html#shortmethodname

      There are no issues that match your filters.

      Category
      Status