src/Phan/Language/Element/Parameter.php

Summary

Maintainability
F
5 days
Test Coverage

File Parameter.php has 555 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Phan\Language\Element;
Severity: Major
Found in src/Phan/Language/Element/Parameter.php - About 1 day to fix

    Parameter has 40 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Parameter extends Variable
    {
        public const REFERENCE_DEFAULT = 1;
        public const REFERENCE_READ_WRITE = 2;
        public const REFERENCE_WRITE_ONLY = 3;
    Severity: Minor
    Found in src/Phan/Language/Element/Parameter.php - About 5 hrs to fix

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

          public function getShortRepresentationForIssue(bool $is_internal = false): string
          {
              $string = '';
      
              $union_type_string = $this->getUnionTypeRepresentationForIssue();
      Severity: Minor
      Found in src/Phan/Language/Element/Parameter.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

      Function fromNode has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function fromNode(
              Context $context,
              CodeBase $code_base,
              Node $node
          ): Parameter {
      Severity: Minor
      Found in src/Phan/Language/Element/Parameter.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 Parameter has 15 public methods. Consider refactoring Parameter to keep number of public methods under 10.
      Open

      class Parameter extends Variable
      {
          public const REFERENCE_DEFAULT = 1;
          public const REFERENCE_READ_WRITE = 2;
          public const REFERENCE_WRITE_ONLY = 3;

      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 Parameter has an overall complexity of 134 which is very high. The configured complexity threshold is 50.
      Open

      class Parameter extends Variable
      {
          public const REFERENCE_DEFAULT = 1;
          public const REFERENCE_READ_WRITE = 2;
          public const REFERENCE_WRITE_ONLY = 3;

      Method fromNode has 70 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function fromNode(
              Context $context,
              CodeBase $code_base,
              Node $node
          ): Parameter {
      Severity: Major
      Found in src/Phan/Language/Element/Parameter.php - About 2 hrs to fix

        Function generateDefaultNodeRepresentation has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            private function generateDefaultNodeRepresentation(bool $is_internal = true): string
            {
                if (is_string($this->default_value_representation)) {
                    return $this->default_value_representation;
                }
        Severity: Minor
        Found in src/Phan/Language/Element/Parameter.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 getShortRepresentationForIssue has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getShortRepresentationForIssue(bool $is_internal = false): string
            {
                $string = '';
        
                $union_type_string = $this->getUnionTypeRepresentationForIssue();
        Severity: Minor
        Found in src/Phan/Language/Element/Parameter.php - About 2 hrs to fix

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

              public static function fromReflectionParameter(
                  \ReflectionParameter $reflection_parameter
              ): Parameter {
                  $flags = 0;
                  // Check to see if it's a pass-by-reference parameter
          Severity: Minor
          Found in src/Phan/Language/Element/Parameter.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 fromReflectionParameter has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function fromReflectionParameter(
                  \ReflectionParameter $reflection_parameter
              ): Parameter {
                  $flags = 0;
                  // Check to see if it's a pass-by-reference parameter
          Severity: Minor
          Found in src/Phan/Language/Element/Parameter.php - About 1 hr to fix

            Method generateDefaultNodeRepresentation has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function generateDefaultNodeRepresentation(bool $is_internal = true): string
                {
                    if (is_string($this->default_value_representation)) {
                        return $this->default_value_representation;
                    }
            Severity: Minor
            Found in src/Phan/Language/Element/Parameter.php - About 1 hr to fix

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

                  private function getUnionTypeRepresentationForIssue(): string
                  {
                      $union_type = $this->getNonVariadicUnionType()->asNormalizedTypes();
                      if ($union_type->isEmpty()) {
                          return '';
              Severity: Minor
              Found in src/Phan/Language/Element/Parameter.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 getUnionTypeRepresentationForIssue has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function getUnionTypeRepresentationForIssue(): string
                  {
                      $union_type = $this->getNonVariadicUnionType()->asNormalizedTypes();
                      if ($union_type->isEmpty()) {
                          return '';
              Severity: Minor
              Found in src/Phan/Language/Element/Parameter.php - About 1 hr to fix

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

                    public function toStubString(bool $is_internal = false): string
                    {
                        $string = '';
                
                        $union_type = $this->getNonVariadicUnionType();
                Severity: Minor
                Found in src/Phan/Language/Element/Parameter.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

                Avoid too many return statements within this method.
                Open

                                    return 'unknown';
                Severity: Major
                Found in src/Phan/Language/Element/Parameter.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return '';
                  Severity: Major
                  Found in src/Phan/Language/Element/Parameter.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return $default_repr;
                    Severity: Major
                    Found in src/Phan/Language/Element/Parameter.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return null;
                      Severity: Major
                      Found in src/Phan/Language/Element/Parameter.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return $union_type_string;
                        Severity: Major
                        Found in src/Phan/Language/Element/Parameter.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return $real_union_type_string;
                          Severity: Major
                          Found in src/Phan/Language/Element/Parameter.php - About 30 mins to fix

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

                                public function __toString(): string
                                {
                                    $string = '';
                                    $flags = $this->getFlags();
                                    if ($flags & self::PARAM_MODIFIER_VISIBILITY_FLAGS) {
                            Severity: Minor
                            Found in src/Phan/Language/Element/Parameter.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 getShortRepresentationForIssue() has an NPath complexity of 912. The configured NPath complexity threshold is 200.
                            Open

                                public function getShortRepresentationForIssue(bool $is_internal = false): string
                                {
                                    $string = '';
                            
                                    $union_type_string = $this->getUnionTypeRepresentationForIssue();

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

                                public static function fromNode(
                                    Context $context,
                                    CodeBase $code_base,
                                    Node $node
                                ): Parameter {

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

                                public static function fromNode(
                                    Context $context,
                                    CodeBase $code_base,
                                    Node $node
                                ): Parameter {

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

                                public function getShortRepresentationForIssue(bool $is_internal = false): string
                                {
                                    $string = '';
                            
                                    $union_type_string = $this->getUnionTypeRepresentationForIssue();

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

                                private function generateDefaultNodeRepresentation(bool $is_internal = true): string
                                {
                                    if (is_string($this->default_value_representation)) {
                                        return $this->default_value_representation;
                                    }

                            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 class Parameter has a coupling between objects value of 29. Consider to reduce the number of dependencies under 13.
                            Open

                            class Parameter extends Variable
                            {
                                public const REFERENCE_DEFAULT = 1;
                                public const REFERENCE_READ_WRITE = 2;
                                public const REFERENCE_WRITE_ONLY = 3;

                            CouplingBetweenObjects

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

                            There are no issues that match your filters.

                            Category
                            Status