jidaikobo-shibata/a11yc

View on GitHub
libs/kontiki/classes/Arr.php

Summary

Maintainability
B
5 hrs
Test Coverage

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

    public static function get($array, $key, $default = null)
    {
        if ( ! is_array($array) and ! $array instanceof \ArrayAccess)
        {
//            throw new \InvalidArgumentException('First parameter must be an array or ArrayAccess object.');
Severity: Minor
Found in libs/kontiki/classes/Arr.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 get has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function get($array, $key, $default = null)
    {
        if ( ! is_array($array) and ! $array instanceof \ArrayAccess)
        {
//            throw new \InvalidArgumentException('First parameter must be an array or ArrayAccess object.');
Severity: Minor
Found in libs/kontiki/classes/Arr.php - About 1 hr to fix

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

        public static function set(&$array, $key, $value = null)
        {
            if (is_null($key))
            {
                $array = $value;
    Severity: Minor
    Found in libs/kontiki/classes/Arr.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 set has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function set(&$array, $key, $value = null)
        {
            if (is_null($key))
            {
                $array = $value;
    Severity: Minor
    Found in libs/kontiki/classes/Arr.php - About 1 hr to fix

      Avoid too many return statements within this method.
      Open

              return $array;
      Severity: Major
      Found in libs/kontiki/classes/Arr.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                            return static::value($default);
        Severity: Major
        Found in libs/kontiki/classes/Arr.php - About 30 mins to fix

          Avoid using Kontiki\count() function in while loops.
          Open

                      while (count($keys) > 1)
                      {
                          $key = array_shift($keys);
          
                          if ( ! isset($array[$key]) or ! is_array($array[$key]))
          Severity: Minor
          Found in libs/kontiki/classes/Arr.php by phpmd

          CountInLoopExpression

          Since: 2.7.0

          Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

          Example

          class Foo {
          
            public function bar()
            {
              $array = array();
          
              for ($i = 0; count($array); $i++) {
                // ...
              }
            }
          }

          Source https://phpmd.org/rules/design.html#countinloopexpression

          There are no issues that match your filters.

          Category
          Status