.phan/plugins/SuspiciousParamOrderPlugin.php

Summary

Maintainability
F
3 days
Test Coverage

Function checkCall has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
Open

    private function checkCall(FunctionInterface $function, array $args, Node $node): void
    {
        $arg_names = [];
        foreach ($args as $i => $arg_node) {
            $name = self::extractName($arg_node);
Severity: Minor
Found in .phan/plugins/SuspiciousParamOrderPlugin.php - About 5 hrs to fix

Cognitive Complexity

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

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

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

Further reading

Method checkCall has 100 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function checkCall(FunctionInterface $function, array $args, Node $node): void
    {
        $arg_names = [];
        foreach ($args as $i => $arg_node) {
            $name = self::extractName($arg_node);
Severity: Major
Found in .phan/plugins/SuspiciousParamOrderPlugin.php - About 4 hrs to fix

    File SuspiciousParamOrderPlugin.php has 326 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    declare(strict_types=1);
    
    use ast\Node;
    Severity: Minor
    Found in .phan/plugins/SuspiciousParamOrderPlugin.php - About 3 hrs to fix

      Function checkMovedArg has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          private function checkMovedArg(FunctionInterface $function, array $args, Node $node, array $arg_names, array $places_set = []): void
          {
              $real_parameters = $function->getRealParameterList();
              $parameters = $function->getParameterList();
              /** @var associative-array<string,?int> maps lowercase param names to their unique index, or null */
      Severity: Minor
      Found in .phan/plugins/SuspiciousParamOrderPlugin.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 SuspiciousParamOrderVisitor has an overall complexity of 64 which is very high. The configured complexity threshold is 50.
      Open

      class SuspiciousParamOrderVisitor extends PluginAwarePostAnalysisVisitor
      {
          // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
          // this is deliberate for issue names
          private const SuspiciousParamOrderInternal = 'PhanPluginSuspiciousParamOrderInternal';

      Method checkMovedArg has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function checkMovedArg(FunctionInterface $function, array $args, Node $node, array $arg_names, array $places_set = []): void
          {
              $real_parameters = $function->getRealParameterList();
              $parameters = $function->getParameterList();
              /** @var associative-array<string,?int> maps lowercase param names to their unique index, or null */
      Severity: Major
      Found in .phan/plugins/SuspiciousParamOrderPlugin.php - About 2 hrs to fix

        Function findCycles has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function findCycles(array $destination_map): array
            {
                $result = [];
                while (count($destination_map) > 0) {
                    reset($destination_map);
        Severity: Minor
        Found in .phan/plugins/SuspiciousParamOrderPlugin.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 checkMovedArg has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            private function checkMovedArg(FunctionInterface $function, array $args, Node $node, array $arg_names, array $places_set = []): void
        Severity: Minor
        Found in .phan/plugins/SuspiciousParamOrderPlugin.php - About 35 mins to fix

          Avoid too many return statements within this method.
          Open

                          return '#' . ($i + 1) . ' (' . trim($param->getUnionType() . ' $' . $param->getName()) . ')';
          Severity: Major
          Found in .phan/plugins/SuspiciousParamOrderPlugin.php - About 30 mins to fix

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

                private static function extractName($arg_node): ?string
                {
                    if (!$arg_node instanceof Node) {
                        return null;
                    }
            Severity: Minor
            Found in .phan/plugins/SuspiciousParamOrderPlugin.php - About 25 mins to fix

            Cognitive Complexity

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

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

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

            Further reading

            The method checkMovedArg() has an NPath complexity of 245. The configured NPath complexity threshold is 200.
            Open

                private function checkMovedArg(FunctionInterface $function, array $args, Node $node, array $arg_names, array $places_set = []): void
                {
                    $real_parameters = $function->getRealParameterList();
                    $parameters = $function->getParameterList();
                    /** @var associative-array<string,?int> maps lowercase param names to their unique index, or null */

            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 checkCall() has an NPath complexity of 15444. The configured NPath complexity threshold is 200.
            Open

                private function checkCall(FunctionInterface $function, array $args, Node $node): void
                {
                    $arg_names = [];
                    foreach ($args as $i => $arg_node) {
                        $name = self::extractName($arg_node);

            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 checkCall() has 110 lines of code. Current threshold is set to 100. Avoid really long methods.
            Open

                private function checkCall(FunctionInterface $function, array $args, Node $node): void
                {
                    $arg_names = [];
                    foreach ($args as $i => $arg_node) {
                        $name = self::extractName($arg_node);

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

                private function checkMovedArg(FunctionInterface $function, array $args, Node $node, array $arg_names, array $places_set = []): void
                {
                    $real_parameters = $function->getRealParameterList();
                    $parameters = $function->getParameterList();
                    /** @var associative-array<string,?int> maps lowercase param names to their unique index, or null */

            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 checkCall() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10.
            Open

                private function checkCall(FunctionInterface $function, array $args, Node $node): void
                {
                    $arg_names = [];
                    foreach ($args as $i => $arg_node) {
                        $name = self::extractName($arg_node);

            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 empty try-catch blocks in visitCall.
            Open

                    } catch (CodeBaseException $_) {
                    }

            EmptyCatchBlock

            Since: 2.7.0

            Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

            Example

            class Foo {
            
              public function bar()
              {
                  try {
                      // ...
                  } catch (Exception $e) {} // empty catch block
              }
            }

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

            Avoid using count() function in while loops.
            Open

                    while (count($destination_map) > 0) {
                        reset($destination_map);
                        $key = (int) key($destination_map);
                        $values = [];
                        while (count($destination_map) > 0) {

            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

            Avoid using count() function in while loops.
            Open

                        while (count($destination_map) > 0) {
                            $values[] = $key;
                            $next = $destination_map[$key];
                            unset($destination_map[$key]);
                            if (in_array($next, $values, true)) {

            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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                public function visitStaticCall(Node $node): void
                {
                    $args = $node->children['args']->children;
                    if (count($args) < 1) {
                        // Can't have a suspicious param order/position if there are no params
            Severity: Major
            Found in .phan/plugins/SuspiciousParamOrderPlugin.php and 1 other location - About 2 hrs to fix
            .phan/plugins/SuspiciousParamOrderPlugin.php on lines 372..396

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 139.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                public function visitMethodCall(Node $node): void
                {
                    $args = $node->children['args']->children;
                    if (count($args) < 1) {
                        // Can't have a suspicious param order/position if there are no params
            Severity: Major
            Found in .phan/plugins/SuspiciousParamOrderPlugin.php and 1 other location - About 2 hrs to fix
            .phan/plugins/SuspiciousParamOrderPlugin.php on lines 402..426

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 139.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

                        $arg_details = implode(' and ', array_map(static function (int $i) use ($args): string {

            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

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

                private static function computeDistance(string $a, string $b): float

            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

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

                private static function computeDistance(string $a, string $b): float

            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

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

                    $lb = strlen($b);

            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

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

                    $la = strlen($a);

            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

            Constant SuspiciousParamPositionInternal should be defined in uppercase
            Open

                private const SuspiciousParamPositionInternal = 'PhanPluginSuspiciousParamPositionInternal';

            ConstantNamingConventions

            Since: 0.2

            Class/Interface constant names should always be defined in uppercase.

            Example

            class Foo {
                const MY_NUM = 0; // ok
                const myTest = ""; // fail
            }

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

            Constant SuspiciousParamPosition should be defined in uppercase
            Open

                private const SuspiciousParamPosition = 'PhanPluginSuspiciousParamPosition';

            ConstantNamingConventions

            Since: 0.2

            Class/Interface constant names should always be defined in uppercase.

            Example

            class Foo {
                const MY_NUM = 0; // ok
                const myTest = ""; // fail
            }

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

            Constant SuspiciousParamOrder should be defined in uppercase
            Open

                private const SuspiciousParamOrder = 'PhanPluginSuspiciousParamOrder';

            ConstantNamingConventions

            Since: 0.2

            Class/Interface constant names should always be defined in uppercase.

            Example

            class Foo {
                const MY_NUM = 0; // ok
                const myTest = ""; // fail
            }

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

            Constant SuspiciousParamOrderInternal should be defined in uppercase
            Open

                private const SuspiciousParamOrderInternal = 'PhanPluginSuspiciousParamOrderInternal';

            ConstantNamingConventions

            Since: 0.2

            Class/Interface constant names should always be defined in uppercase.

            Example

            class Foo {
                const MY_NUM = 0; // ok
                const myTest = ""; // fail
            }

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

            There are no issues that match your filters.

            Category
            Status