efureev/u.php

View on GitHub
src/uArray.php

Summary

Maintainability
D
1 day
Test Coverage

Function save has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    public static function save($key, array &$array, $value, $replace = true)
    {
        if ($key === '') {
            $array[ $key ] = $value;

Severity: Minor
Found in src/uArray.php - About 4 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 uArray has an overall complexity of 72 which is very high. The configured complexity threshold is 50.
Open

class uArray
{

    /**
     * Проверяет, является ли массив ассоциативным
Severity: Minor
Found in src/uArray.php by phpmd

Method parseAndValidateKeys has 72 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private static function parseAndValidateKeys($key, array &$array, $mode = '')
    {
        $parseInfo = [
            'keys'         => [],
            'lastKey'      => '',
Severity: Major
Found in src/uArray.php - About 2 hrs to fix

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

        private static function parseAndValidateKeys($key, array &$array, $mode = '')
        {
            $parseInfo = [
                'keys'         => [],
                'lastKey'      => '',
    Severity: Minor
    Found in src/uArray.php - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function isAssociative has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function isAssociative($array, $allStrings = true)
        {
            if (!is_array($array) || empty($array)) {
                return false;
            }
    Severity: Minor
    Found in src/uArray.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 save has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function save($key, array &$array, $value, $replace = true)
        {
            if ($key === '') {
                $array[ $key ] = $value;
    
    
    Severity: Minor
    Found in src/uArray.php - About 1 hr to fix

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

          public static function isIndexed(array $array, $consecutive = false)
          {
              if (empty($array)) {
                  return true;
              }
      Severity: Minor
      Found in src/uArray.php - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

          public static function get($key, array $array, $default = null, $ignoreString = true)
          {
              if ($key === '') {
                  if (!array_key_exists((string)$key, $array)) {
                      return $default;
      Severity: Minor
      Found in src/uArray.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 false;
      Severity: Major
      Found in src/uArray.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                return ($parseInfo['completed'] && ($parseInfo['isExists'] || $parseInfo['isString'])) ? $parseInfo['value'] : $default;
        Severity: Major
        Found in src/uArray.php - About 30 mins to fix

          The method parseAndValidateKeys() has an NPath complexity of 9720. The configured NPath complexity threshold is 200.
          Open

              private static function parseAndValidateKeys($key, array &$array, $mode = '')
              {
                  $parseInfo = [
                      'keys'         => [],
                      'lastKey'      => '',
          Severity: Minor
          Found in src/uArray.php by phpmd

          NPathComplexity

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

          The method save() has an NPath complexity of 228. The configured NPath complexity threshold is 200.
          Open

              public static function save($key, array &$array, $value, $replace = true)
              {
                  if ($key === '') {
                      $array[ $key ] = $value;
          
          
          Severity: Minor
          Found in src/uArray.php by phpmd

          NPathComplexity

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

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

              public static function get($key, array $array, $default = null, $ignoreString = true)
              {
                  if ($key === '') {
                      if (!array_key_exists((string)$key, $array)) {
                          return $default;
          Severity: Minor
          Found in src/uArray.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 save() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
          Open

              public static function save($key, array &$array, $value, $replace = true)
              {
                  if ($key === '') {
                      $array[ $key ] = $value;
          
          
          Severity: Minor
          Found in src/uArray.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 parseAndValidateKeys() has a Cyclomatic Complexity of 21. The configured cyclomatic complexity threshold is 10.
          Open

              private static function parseAndValidateKeys($key, array &$array, $mode = '')
              {
                  $parseInfo = [
                      'keys'         => [],
                      'lastKey'      => '',
          Severity: Minor
          Found in src/uArray.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

          Avoid using undefined variables such as '$mCurSource' which will lead to PHP notices.
          Open

                              $mCurSource[ $key ] = [];
          Severity: Minor
          Found in src/uArray.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

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

              public static function save($key, array &$array, $value, $replace = true)
          Severity: Minor
          Found in src/uArray.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

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

              public static function get($key, array $array, $default = null, $ignoreString = true)
          Severity: Minor
          Found in src/uArray.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

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

              public static function isIndexed(array $array, $consecutive = false)
          Severity: Minor
          Found in src/uArray.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

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

              public static function isAssociative($array, $allStrings = true)
          Severity: Minor
          Found in src/uArray.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 assigning values to variables in if clauses and the like (line '319', column '26').
          Open

              private static function parseAndValidateKeys($key, array &$array, $mode = '')
              {
                  $parseInfo = [
                      'keys'         => [],
                      'lastKey'      => '',
          Severity: Minor
          Found in src/uArray.php by phpmd

          IfStatementAssignment

          Since: 2.7.0

          Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($foo = 'bar') { // possible typo
                      // ...
                  }
                  if ($baz = 0) { // always false
                      // ...
                  }
              }
          }

          Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

          Avoid unused local variables such as '$mCurSource'.
          Open

                              $mCurSource[ $key ] = [];
          Severity: Minor
          Found in src/uArray.php by phpmd

          UnusedLocalVariable

          Since: 0.2

          Detects when a local variable is declared and/or assigned, but not used.

          Example

          class Foo {
              public function doSomething()
              {
                  $i = 5; // Unused
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

          Avoid unused local variables such as '$value'.
          Open

                      foreach ($array as $key => $value) {
          Severity: Minor
          Found in src/uArray.php by phpmd

          UnusedLocalVariable

          Since: 0.2

          Detects when a local variable is declared and/or assigned, but not used.

          Example

          class Foo {
              public function doSomething()
              {
                  $i = 5; // Unused
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

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

                      function ($m) use (&$parseInfo, &$array) {
          Severity: Minor
          Found in src/uArray.php by phpmd

          ShortVariable

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

          The class uArray is not named in CamelCase.
          Open

          class uArray
          {
          
              /**
               * Проверяет, является ли массив ассоциативным
          Severity: Minor
          Found in src/uArray.php by phpmd

          CamelCaseClassName

          Since: 0.2

          It is considered best practice to use the CamelCase notation to name classes.

          Example

          class class_name {
          }

          Source

          Only one argument is allowed per line in a multi-line function call
          Open

                      }, $key);
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Line exceeds 120 characters; contains 143 characters
          Open

                  $parseInfo['isBroken'] = (bool)preg_replace_callback(['/(?J:\[([\'"])(?<el>.*?)\1\]|(?<el>\]?[^\[]+)|\[(?<el>(?:[^\[\]]+|(?R))*)\])/'],
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Inline control structures are not allowed
          Open

                  if (!count($array)) return null;
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Line exceeds 120 characters; contains 128 characters
          Open

                  return ($parseInfo['completed'] && ($parseInfo['isExists'] || $parseInfo['isString'])) ? $parseInfo['value'] : $default;
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Line exceeds 120 characters; contains 145 characters
          Open

               * то масссив является ассоциативным, если хотя бы один ключ является строкой.
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Line exceeds 120 characters; contains 132 characters
          Open

               * Массив индексируем, если все ключи массива - цифры. Если `$consecutive` == true,
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Inline control structures are not allowed
          Open

                  if (!count($array)) return null;
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Opening parenthesis of a multi-line function call must be the last content on the line
          Open

                              if (($parseInfo['isExists'] = array_key_exists((string)$m['el'],
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Opening parenthesis of a multi-line function call must be the last content on the line
          Open

                  $parseInfo['isBroken'] = (bool)preg_replace_callback(['/(?J:\[([\'"])(?<el>.*?)\1\]|(?<el>\]?[^\[]+)|\[(?<el>(?:[^\[\]]+|(?R))*)\])/'],
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Closing parenthesis of a multi-line function call must be on a line by itself
          Open

                      }, $key);
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Class name "uArray" is not in camel caps format
          Open

          class uArray
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Multi-line function call not indented correctly; expected 8 spaces but found 12
          Open

                      }, $key);
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Closing parenthesis of a multi-line function call must be on a line by itself
          Open

                                      $parseInfo['currEl']) && is_array($parseInfo['currEl']))
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          Multi-line function call not indented correctly; expected 20 spaces but found 28
          Open

                                      $parseInfo['currEl']) && is_array($parseInfo['currEl']))
          Severity: Minor
          Found in src/uArray.php by phpcodesniffer

          There are no issues that match your filters.

          Category
          Status