src/Phan/Language/Type/FunctionLikeDeclarationType.php

Summary

Maintainability
F
5 days
Test Coverage

FunctionLikeDeclarationType has 110 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class FunctionLikeDeclarationType extends Type implements FunctionInterface
{
    // Subclasses will override this
    public const NAME = '';

Severity: Major
Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 2 days to fix

    File FunctionLikeDeclarationType.php has 667 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    declare(strict_types=1);
    
    namespace Phan\Language\Type;
    Severity: Major
    Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 1 day to fix

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

      abstract class FunctionLikeDeclarationType extends Type implements FunctionInterface
      {
          // Subclasses will override this
          public const NAME = '';
      
      

      The class FunctionLikeDeclarationType has 30 public methods. Consider refactoring FunctionLikeDeclarationType to keep number of public methods under 10.
      Open

      abstract class FunctionLikeDeclarationType extends Type implements FunctionInterface
      {
          // Subclasses will override this
          public const NAME = '';
      
      

      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 FunctionLikeDeclarationType has 31 non-getter- and setter-methods. Consider refactoring FunctionLikeDeclarationType to keep number of methods under 25.
      Open

      abstract class FunctionLikeDeclarationType extends Type implements FunctionInterface
      {
          // Subclasses will override this
          public const NAME = '';
      
      

      TooManyMethods

      Since: 0.1

      A class with too many 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'.

      The default was changed from 10 to 25 in PHPMD 2.3.

      Example

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

      Function getTemplateTypeExtractorClosure has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getTemplateTypeExtractorClosure(CodeBase $code_base, TemplateType $template_type): ?Closure
          {
              // Create a closure to extract types for the template type from the return type and param types.
              $closure = $this->getReturnTemplateTypeExtractorClosure($code_base, $template_type);
              foreach ($this->params as $i => $param) {
      Severity: Minor
      Found in src/Phan/Language/Type/FunctionLikeDeclarationType.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 canCastToNonNullableTypeHandlingTemplates has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function canCastToNonNullableTypeHandlingTemplates(Type $type, CodeBase $code_base): bool
          {
              if (parent::canCastToNonNullableTypeHandlingTemplates($type, $code_base)) {
                  return true;
              }
      Severity: Minor
      Found in src/Phan/Language/Type/FunctionLikeDeclarationType.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

      The class FunctionLikeDeclarationType has 108 public methods and attributes. Consider reducing the number of public items to less than 45.
      Open

      abstract class FunctionLikeDeclarationType extends Type implements FunctionInterface
      {
          // Subclasses will override this
          public const NAME = '';
      
      

      ExcessivePublicCount

      Since: 0.1

      A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.

      Example

      public class Foo {
          public $value;
          public $something;
          public $var;
          // [... more more public attributes ...]
      
          public function doWork() {}
          public function doMoreWork() {}
          public function doWorkAgain() {}
          // [... more more public methods ...]
      }

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

      Method getTemplateTypeExtractorClosure has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getTemplateTypeExtractorClosure(CodeBase $code_base, TemplateType $template_type): ?Closure
          {
              // Create a closure to extract types for the template type from the return type and param types.
              $closure = $this->getReturnTemplateTypeExtractorClosure($code_base, $template_type);
              foreach ($this->params as $i => $param) {
      Severity: Minor
      Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 1 hr to fix

        Method canCastToNonNullableTypeHandlingTemplates has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function canCastToNonNullableTypeHandlingTemplates(Type $type, CodeBase $code_base): bool
            {
                if (parent::canCastToNonNullableTypeHandlingTemplates($type, $code_base)) {
                    return true;
                }
        Severity: Minor
        Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 1 hr to fix

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

              public function canCastToNonNullableFunctionLikeDeclarationType(FunctionLikeDeclarationType $type): bool
              {
                  if ($this->required_param_count > $type->required_param_count) {
                      return false;
                  }
          Severity: Minor
          Found in src/Phan/Language/Type/FunctionLikeDeclarationType.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 __construct has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function __construct(FileRef $file_ref, array $params, UnionType $return_type, bool $returns_reference, bool $is_nullable)
              {
                  parent::__construct('\\', static::NAME, [], $is_nullable);
                  $this->file_ref = FileRef::copyFileRef($file_ref);
                  $this->params = $params;
          Severity: Minor
          Found in src/Phan/Language/Type/FunctionLikeDeclarationType.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 __construct has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public function __construct(FileRef $file_ref, array $params, UnionType $return_type, bool $returns_reference, bool $is_nullable)
          Severity: Minor
          Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 35 mins to fix

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

                public function toFunctionSignatureArray(): array
                {
                    // no need for returns ref yet
                    $return_type = $this->return_type;
                    $stub = [$return_type->__toString()];
            Severity: Minor
            Found in src/Phan/Language/Type/FunctionLikeDeclarationType.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/Phan/Language/Type/FunctionLikeDeclarationType.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return true;
              Severity: Major
              Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return false;
                Severity: Major
                Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return false;
                  Severity: Major
                  Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return false;
                    Severity: Major
                    Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return true;
                      Severity: Major
                      Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 30 mins to fix

                        The class FunctionLikeDeclarationType has 1054 lines of code. Current threshold is 1000. Avoid really long classes.
                        Open

                        abstract class FunctionLikeDeclarationType extends Type implements FunctionInterface
                        {
                            // Subclasses will override this
                            public const NAME = '';
                        
                        

                        The method canCastToNonNullableTypeHandlingTemplates() has an NPath complexity of 320. The configured NPath complexity threshold is 200.
                        Open

                            protected function canCastToNonNullableTypeHandlingTemplates(Type $type, CodeBase $code_base): bool
                            {
                                if (parent::canCastToNonNullableTypeHandlingTemplates($type, $code_base)) {
                                    return true;
                                }

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

                            protected function canCastToNonNullableTypeHandlingTemplates(Type $type, CodeBase $code_base): bool
                            {
                                if (parent::canCastToNonNullableTypeHandlingTemplates($type, $code_base)) {
                                    return true;
                                }

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

                        abstract class FunctionLikeDeclarationType extends Type implements FunctionInterface
                        {
                            // Subclasses will override this
                            public const NAME = '';
                        
                        

                        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

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

                            public function getRealParameterForCaller(int $i): ?Parameter

                        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 $i. Configured minimum length is 3.
                        Open

                            public function getClosureParameterForArgument(int $i): ?ClosureDeclarationParameter

                        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 $i. Configured minimum length is 3.
                        Open

                            public function getParameterForCaller(int $i): ?Parameter

                        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

                        There are no issues that match your filters.

                        Category
                        Status