src/Phan/Language/Element/FunctionTrait.php

Summary

Maintainability
F
1 wk
Test Coverage

File FunctionTrait.php has 1182 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/FunctionTrait.php - About 3 days to fix

    Function analyzeReturnTypesInner has a Cognitive Complexity of 74 (exceeds 5 allowed). Consider refactoring.
    Open

        private function analyzeReturnTypesInner(CodeBase $code_base): void
        {
            if ($this->isPHPInternal()) {
                // nothing to do, no known Node
                return;
    Severity: Minor
    Found in src/Phan/Language/Element/FunctionTrait.php - About 1 day 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 addParamToScopeOfFunctionOrMethod has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function addParamToScopeOfFunctionOrMethod(
            Context $context,
            CodeBase $code_base,
            FunctionInterface $function,
            Comment $comment,
    Severity: Minor
    Found in src/Phan/Language/Element/FunctionTrait.php - About 6 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 analyzeReturnTypesInner has 127 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function analyzeReturnTypesInner(CodeBase $code_base): void
        {
            if ($this->isPHPInternal()) {
                // nothing to do, no known Node
                return;
    Severity: Major
    Found in src/Phan/Language/Element/FunctionTrait.php - About 5 hrs to fix

      Method addParamToScopeOfFunctionOrMethod has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function addParamToScopeOfFunctionOrMethod(
              Context $context,
              CodeBase $code_base,
              FunctionInterface $function,
              Comment $comment,
      Severity: Major
      Found in src/Phan/Language/Element/FunctionTrait.php - About 3 hrs to fix

        Method addParamsToScopeOfFunctionOrMethod has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function addParamsToScopeOfFunctionOrMethod(
                Context $context,
                CodeBase $code_base,
                FunctionInterface $function,
                Comment $comment
        Severity: Major
        Found in src/Phan/Language/Element/FunctionTrait.php - About 2 hrs to fix

          Method addClosureForDependentTemplateType has 53 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function addClosureForDependentTemplateType(CodeBase $code_base, Context $context, array $template_type_list): void
              {
                  if ($this->hasDependentReturnType()) {
                      // We already added this or this conflicts with a plugin.
                      return;
          Severity: Major
          Found in src/Phan/Language/Element/FunctionTrait.php - About 2 hrs to fix

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

                public static function addParamsToScopeOfFunctionOrMethod(
                    Context $context,
                    CodeBase $code_base,
                    FunctionInterface $function,
                    Comment $comment
            Severity: Minor
            Found in src/Phan/Language/Element/FunctionTrait.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 createClosureForUnionTypeExtractorAndAssertionType has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function createClosureForUnionTypeExtractorAndAssertionType(Closure $union_type_extractor, int $assertion_type, int $i): ?Closure
                {
                    switch ($assertion_type) {
                        case Assertion::IS_OF_TYPE:
                            /**
            Severity: Minor
            Found in src/Phan/Language/Element/FunctionTrait.php - About 1 hr to fix

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

                  public function getTemplateTypeExtractorClosure(CodeBase $code_base, TemplateType $template_type, int $skip_index = null): ?Closure
                  {
                      $closure = null;
                      foreach ($this->parameter_list as $i => $parameter) {
                          if ($i === $skip_index) {
              Severity: Minor
              Found in src/Phan/Language/Element/FunctionTrait.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 getCommentParamAssertionClosure has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getCommentParamAssertionClosure(CodeBase $code_base): ?Closure
                  {
                      if (!\is_object($this->comment)) {
                          return null;
                      }
              Severity: Minor
              Found in src/Phan/Language/Element/FunctionTrait.php - About 1 hr to fix

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

                    public function inheritRealParameterDefaults(): void
                    {
                        foreach ($this->real_parameter_list as $i => $real_parameter) {
                            $parameter = $this->parameter_list[$i] ?? null;
                            if (!$parameter || $parameter->isVariadic() || $real_parameter->isVariadic()) {
                Severity: Minor
                Found in src/Phan/Language/Element/FunctionTrait.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 getCommentParamAssertionClosure has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function getCommentParamAssertionClosure(CodeBase $code_base): ?Closure
                    {
                        if (!\is_object($this->comment)) {
                            return null;
                        }
                Severity: Minor
                Found in src/Phan/Language/Element/FunctionTrait.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 addClosureForDependentTemplateType has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function addClosureForDependentTemplateType(CodeBase $code_base, Context $context, array $template_type_list): void
                    {
                        if ($this->hasDependentReturnType()) {
                            // We already added this or this conflicts with a plugin.
                            return;
                Severity: Minor
                Found in src/Phan/Language/Element/FunctionTrait.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 toFunctionSignatureArray has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function toFunctionSignatureArray(): array
                    {
                        $return_type = $this->getUnionType();
                        $stub = [$return_type->__toString()];
                        '@phan-var array<mixed,string> $stub';  // TODO: Should not warn about PhanTypeMismatchDimFetch in isset below
                Severity: Minor
                Found in src/Phan/Language/Element/FunctionTrait.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 getTemplateTypeExtractorClosure has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function getTemplateTypeExtractorClosure(CodeBase $code_base, TemplateType $template_type, int $skip_index = null): ?Closure
                    {
                        $closure = null;
                        foreach ($this->parameter_list as $i => $parameter) {
                            if ($i === $skip_index) {
                Severity: Minor
                Found in src/Phan/Language/Element/FunctionTrait.php - About 1 hr to fix

                  Function isReturnTypeModifiable has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function isReturnTypeModifiable(): bool
                      {
                          if ($this->isReturnTypeUndefined()) {
                              return true;
                          }
                  Severity: Minor
                  Found in src/Phan/Language/Element/FunctionTrait.php - About 55 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 makeAssertionUnionTypeExtractor has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private function makeAssertionUnionTypeExtractor(CodeBase $code_base, UnionType $type, int $asserted_param_index): ?Closure
                      {
                          if (!$this->comment) {
                              return null;
                          }
                  Severity: Minor
                  Found in src/Phan/Language/Element/FunctionTrait.php - About 55 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 analyzeWithNewParams has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function analyzeWithNewParams(Context $context, CodeBase $code_base, array $parameter_list): Context
                      {
                          $hash = $this->computeParameterListHash($parameter_list);
                          $has_pass_by_reference_variable = null;
                          // Nothing to do, except if PassByReferenceVariable was used
                  Severity: Minor
                  Found in src/Phan/Language/Element/FunctionTrait.php - About 55 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 inferNormalizedTypesOfDefault has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private static function inferNormalizedTypesOfDefault(UnionType $default_type): UnionType
                      {
                          $type_set = $default_type->getTypeSet();
                          if (\count($type_set) === 0) {
                              return $default_type;
                  Severity: Minor
                  Found in src/Phan/Language/Element/FunctionTrait.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 addParamToScopeOfFunctionOrMethod has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                          Context $context,
                          CodeBase $code_base,
                          FunctionInterface $function,
                          Comment $comment,
                          int $parameter_offset,
                  Severity: Minor
                  Found in src/Phan/Language/Element/FunctionTrait.php - About 45 mins to fix

                    Consider simplifying this complex logical expression.
                    Open

                                    if ($this instanceof Func || ($this instanceof Method && ($this->isPrivate() || $this->isEffectivelyFinal() || $this->isMagicAndVoid() || $this->getClass($code_base)->isFinal()))) {
                                        $this->setUnionType(VoidType::instance(false)->asPHPDocUnionType());
                                    }
                    Severity: Major
                    Found in src/Phan/Language/Element/FunctionTrait.php - About 40 mins to fix

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

                          private function isTemplateTypeUsed(TemplateType $type): bool
                          {
                              if ($this->getUnionType()->usesTemplateType($type)) {
                                  // used in `@return`
                                  return true;
                      Severity: Minor
                      Found in src/Phan/Language/Element/FunctionTrait.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

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

                          private function computeNeedsRecursiveAnalysis(): bool
                          {
                              if (!$this->getNode()) {
                                  // E.g. this can be the case for magic methods, internal methods, stubs, etc.
                                  return false;
                      Severity: Minor
                      Found in src/Phan/Language/Element/FunctionTrait.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 true;
                      Severity: Major
                      Found in src/Phan/Language/Element/FunctionTrait.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

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

                          Avoid too many return statements within this method.
                          Open

                                  return $closure;
                          Severity: Major
                          Found in src/Phan/Language/Element/FunctionTrait.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/FunctionTrait.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return $function->getUnionType()->withTemplateParameterTypeMap($template_type_map);
                              Severity: Major
                              Found in src/Phan/Language/Element/FunctionTrait.php - About 30 mins to fix

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

                                    private function getPluginForParamAssertionMap(CodeBase $code_base, array $param_assertion_map, ?Closure $closure): ?Closure
                                    {
                                        foreach ($param_assertion_map as $param_name => $assertion) {
                                            $i = $this->getParamIndexForName($param_name);
                                            if ($i === null) {
                                Severity: Minor
                                Found in src/Phan/Language/Element/FunctionTrait.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 addParamsToScopeOfFunctionOrMethod() has an NPath complexity of 456. The configured NPath complexity threshold is 200.
                                Open

                                    public static function addParamsToScopeOfFunctionOrMethod(
                                        Context $context,
                                        CodeBase $code_base,
                                        FunctionInterface $function,
                                        Comment $comment

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

                                    public static function addParamToScopeOfFunctionOrMethod(
                                        Context $context,
                                        CodeBase $code_base,
                                        FunctionInterface $function,
                                        Comment $comment,

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

                                    private function analyzeReturnTypesInner(CodeBase $code_base): void
                                    {
                                        if ($this->isPHPInternal()) {
                                            // nothing to do, no known Node
                                            return;

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

                                    public static function addParamToScopeOfFunctionOrMethod(
                                        Context $context,
                                        CodeBase $code_base,
                                        FunctionInterface $function,
                                        Comment $comment,

                                The method analyzeReturnTypesInner() has 151 lines of code. Current threshold is set to 100. Avoid really long methods.
                                Open

                                    private function analyzeReturnTypesInner(CodeBase $code_base): void
                                    {
                                        if ($this->isPHPInternal()) {
                                            // nothing to do, no known Node
                                            return;

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

                                    private function analyzeReturnTypesInner(CodeBase $code_base): void
                                    {
                                        if ($this->isPHPInternal()) {
                                            // nothing to do, no known Node
                                            return;

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

                                    public static function addParamToScopeOfFunctionOrMethod(
                                        Context $context,
                                        CodeBase $code_base,
                                        FunctionInterface $function,
                                        Comment $comment,

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

                                    public static function addParamsToScopeOfFunctionOrMethod(
                                        Context $context,
                                        CodeBase $code_base,
                                        FunctionInterface $function,
                                        Comment $comment

                                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 analyzeReturnTypes.
                                Open

                                        } catch (RecursionDepthException $_) {
                                        }

                                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

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

                                            case Assertion::IS_OF_TYPE:
                                                /**
                                                 * @param list<Node|mixed> $args
                                                 */
                                                return static function (CodeBase $code_base, Context $context, FunctionInterface $unused_function, array $args, ?Node $unused_node) use ($i, $union_type_extractor): void {
                                Severity: Major
                                Found in src/Phan/Language/Element/FunctionTrait.php and 1 other location - About 2 hrs to fix
                                src/Phan/Language/Element/FunctionTrait.php on lines 1751..1764

                                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

                                            case Assertion::IS_NOT_OF_TYPE:
                                                /**
                                                 * @param list<Node|mixed> $args
                                                 */
                                                return static function (CodeBase $code_base, Context $context, FunctionInterface $unused_function, array $args, ?Node $unused_node) use ($i, $union_type_extractor): void {
                                Severity: Major
                                Found in src/Phan/Language/Element/FunctionTrait.php and 1 other location - About 2 hrs to fix
                                src/Phan/Language/Element/FunctionTrait.php on lines 1737..1750

                                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

                                            case Assertion::IS_FALSE:
                                                /**
                                                 * @param list<Node|mixed> $args
                                                 */
                                                return static function (CodeBase $code_base, Context $context, FunctionInterface $unused_function, array $args, ?Node $unused_node) use ($i): void {
                                Severity: Major
                                Found in src/Phan/Language/Element/FunctionTrait.php and 1 other location - About 1 hr to fix
                                src/Phan/Language/Element/FunctionTrait.php on lines 1765..1777

                                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 117.

                                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

                                            case Assertion::IS_TRUE:
                                                /**
                                                 * @param list<Node|mixed> $args
                                                 */
                                                return static function (CodeBase $code_base, Context $context, FunctionInterface $unused_function, array $args, ?Node $unused_node) use ($i): void {
                                Severity: Major
                                Found in src/Phan/Language/Element/FunctionTrait.php and 1 other location - About 1 hr to fix
                                src/Phan/Language/Element/FunctionTrait.php on lines 1778..1790

                                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 117.

                                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 getRealParameterForCaller(int $i): ?Parameter
                                    {
                                        $list = $this->real_parameter_list;
                                        if (count($list) === 0) {
                                            return null;
                                Severity: Major
                                Found in src/Phan/Language/Element/FunctionTrait.php and 1 other location - About 1 hr to fix
                                src/Phan/Language/Element/FunctionTrait.php on lines 493..508

                                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 115.

                                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 getParameterForCaller(int $i): ?Parameter
                                    {
                                        $list = $this->parameter_list;
                                        if (count($list) === 0) {
                                            return null;
                                Severity: Major
                                Found in src/Phan/Language/Element/FunctionTrait.php and 1 other location - About 1 hr to fix
                                src/Phan/Language/Element/FunctionTrait.php on lines 519..534

                                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 115.

                                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

                                            $i = $this->getParamIndexForName($param_name);

                                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 static function createClosureForUnionTypeExtractorAndAssertionType(Closure $union_type_extractor, int $assertion_type, int $i): ?Closure

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

                                    abstract protected function memoize(string $key, Closure $fn);

                                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 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 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

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

                                    public function createClosureForAssertion(CodeBase $code_base, Assertion $assertion, int $i): ?Closure

                                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 'getPhanFlagsHasState()' method which returns a boolean should be named 'is...()' or 'has...()'
                                Open

                                    abstract public function getPhanFlagsHasState(int $bits): bool;

                                BooleanGetMethodName

                                Since: 0.2

                                Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

                                Example

                                class Foo {
                                    /**
                                     * @return boolean
                                     */
                                    public function getFoo() {} // bad
                                    /**
                                     * @return bool
                                     */
                                    public function isFoo(); // ok
                                    /**
                                     * @return boolean
                                     */
                                    public function getFoo($bar); // ok, unless checkParameterizedMethods=true
                                }

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

                                There are no issues that match your filters.

                                Category
                                Status