.phan/plugins/UnknownElementTypePlugin.php

Summary

Maintainability
F
5 days
Test Coverage

Method analyzeFunction has 118 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function analyzeFunction(
        CodeBase $code_base,
        Func $function
    ): void {
        // NOTE: Placeholders can be found in \Phan\Issue::uncolored_format_string_for_replace
Severity: Major
Found in .phan/plugins/UnknownElementTypePlugin.php - About 4 hrs to fix

    File UnknownElementTypePlugin.php has 333 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

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

      Function analyzeFunction has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public function analyzeFunction(
              CodeBase $code_base,
              Func $function
          ): void {
              // NOTE: Placeholders can be found in \Phan\Issue::uncolored_format_string_for_replace
      Severity: Minor
      Found in .phan/plugins/UnknownElementTypePlugin.php - About 3 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Method analyzeMethod has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function analyzeMethod(
              CodeBase $code_base,
              Method $method
          ): void {
              if ($method->getFQSEN() !== $method->getRealDefiningFQSEN()) {
      Severity: Major
      Found in .phan/plugins/UnknownElementTypePlugin.php - About 2 hrs to fix

        Method performChecks has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function performChecks(
                AddressableElement $element,
                string $issue_type_for_empty,
                string $message_for_empty,
                string $issue_type_for_unknown_array,
        Severity: Minor
        Found in .phan/plugins/UnknownElementTypePlugin.php - About 1 hr to fix

          Method emitIssueAndSuggestion has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  CodeBase $code_base,
                  Context $context,
                  string $issue_type,
                  string $message,
                  array $args,
          Severity: Minor
          Found in .phan/plugins/UnknownElementTypePlugin.php - About 45 mins to fix

            Method performChecks has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                    AddressableElement $element,
                    string $issue_type_for_empty,
                    string $message_for_empty,
                    string $issue_type_for_unknown_array,
                    string $message_for_unknown_array
            Severity: Minor
            Found in .phan/plugins/UnknownElementTypePlugin.php - About 35 mins to fix

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

                  private function performChecks(
                      AddressableElement $element,
                      string $issue_type_for_empty,
                      string $message_for_empty,
                      string $issue_type_for_unknown_array,
              Severity: Minor
              Found in .phan/plugins/UnknownElementTypePlugin.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 analyzeMethod has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function analyzeMethod(
                      CodeBase $code_base,
                      Method $method
                  ): void {
                      if ($method->getFQSEN() !== $method->getRealDefiningFQSEN()) {
              Severity: Minor
              Found in .phan/plugins/UnknownElementTypePlugin.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

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

                  public function analyzeFunction(
                      CodeBase $code_base,
                      Func $function
                  ): void {
                      // NOTE: Placeholders can be found in \Phan\Issue::uncolored_format_string_for_replace

              The method analyzeFunction() has an NPath complexity of 720. The configured NPath complexity threshold is 200.
              Open

                  public function analyzeFunction(
                      CodeBase $code_base,
                      Func $function
                  ): void {
                      // NOTE: Placeholders can be found in \Phan\Issue::uncolored_format_string_for_replace

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

                  public function analyzeMethod(
                      CodeBase $code_base,
                      Method $method
                  ): void {
                      if ($method->getFQSEN() !== $method->getRealDefiningFQSEN()) {

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

                  public function analyzeFunction(
                      CodeBase $code_base,
                      Func $function
                  ): void {
                      // NOTE: Placeholders can be found in \Phan\Issue::uncolored_format_string_for_replace

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

              class UnknownElementTypePlugin extends PluginV3 implements
                  AnalyzeFunctionCapability,
                  AnalyzeMethodCapability,
                  AnalyzePropertyCapability,
                  FinalizeProcessCapability

              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

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

                      $method->addFunctionCallAnalyzer(
                          /**
                           * @param list<mixed> $args
                           */
                          static function (CodeBase $code_base, Context $context, Method $unused_method, array $args, Node $unused_node) use ($warning_closures, &$inferred_types): void {
              Severity: Major
              Found in .phan/plugins/UnknownElementTypePlugin.php and 1 other location - About 4 hrs to fix
              .phan/plugins/UnknownElementTypePlugin.php on lines 332..354

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

              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

                      $function->addFunctionCallAnalyzer(
                          /**
                           * @param list<mixed> $args
                           */
                          static function (CodeBase $code_base, Context $context, Func $unused_function, array $args, Node $unused_node) use ($warning_closures, &$inferred_types): void {
              Severity: Major
              Found in .phan/plugins/UnknownElementTypePlugin.php and 1 other location - About 4 hrs to fix
              .phan/plugins/UnknownElementTypePlugin.php on lines 114..136

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

              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

                      if ($function->getUnionType()->isEmpty()) {
                          if ($function->getFQSEN()->isClosure()) {
                              $issue = 'PhanPluginUnknownClosureReturnType';
                              $message = 'Closure {FUNCTION} has no declared or inferred return type';
                          } else {
              Severity: Major
              Found in .phan/plugins/UnknownElementTypePlugin.php and 1 other location - About 4 hrs to fix
              .phan/plugins/UnknownElementTypePlugin.php on lines 257..280

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

              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

                      } elseif (self::isRegularArray($function->getUnionType())) {
                          if ($function->getFQSEN()->isClosure()) {
                              $issue = 'PhanPluginUnknownArrayClosureReturnType';
                              $message = 'Closure {FUNCTION} has a return type of array, but does not specify key or value types';
                          } else {
              Severity: Major
              Found in .phan/plugins/UnknownElementTypePlugin.php and 1 other location - About 4 hrs to fix
              .phan/plugins/UnknownElementTypePlugin.php on lines 234..280

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

              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

                          } elseif (self::isRegularArray($parameter->getUnionType())) {
                              if ($function->getFQSEN()->isClosure()) {
                                  $issue = 'PhanPluginUnknownArrayClosureParamType';
                                  $message = 'Closure {FUNCTION} has a parameter type of array for ${PARAMETER}, but does not specify any key types or value types';
                              } else {
              Severity: Major
              Found in .phan/plugins/UnknownElementTypePlugin.php and 1 other location - About 3 hrs to fix
              .phan/plugins/UnknownElementTypePlugin.php on lines 284..322

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

              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

                          if ($parameter->getUnionType()->isEmpty()) {
                              if ($function->getFQSEN()->isClosure()) {
                                  $issue = 'PhanPluginUnknownClosureParamType';
                                  $message = 'Closure {FUNCTION} has no declared or inferred return type for ${PARAMETER}';
                              } else {
              Severity: Major
              Found in .phan/plugins/UnknownElementTypePlugin.php and 1 other location - About 3 hrs to fix
              .phan/plugins/UnknownElementTypePlugin.php on lines 303..322

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

              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

                          } elseif (self::isRegularArray($parameter->getUnionType())) {
                              $warning_closures[$i] = static function () use ($code_base, $parameter, $method, $i, &$inferred_types): void {
                                  $suggestion = self::suggestionFromUnionTypeNotRegularArray($inferred_types[$i] ?? null);
                                  self::emitIssueAndSuggestion(
                                      $code_base,
              Severity: Major
              Found in .phan/plugins/UnknownElementTypePlugin.php and 1 other location - About 1 hr to fix
              .phan/plugins/UnknownElementTypePlugin.php on lines 80..104

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

              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

                          if ($parameter->getUnionType()->isEmpty()) {
                              $warning_closures[$i] = static function () use ($code_base, $parameter, $method, $i, &$inferred_types): void {
                                  $suggestion = self::suggestionFromUnionType($inferred_types[$i] ?? null);
                                  self::emitIssueAndSuggestion(
                                      $code_base,
              Severity: Major
              Found in .phan/plugins/UnknownElementTypePlugin.php and 1 other location - About 1 hr to fix
              .phan/plugins/UnknownElementTypePlugin.php on lines 92..104

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

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

                      $this->deferred_checks[$function->getFQSEN()->__toString()] = static function (CodeBase $_) use ($warning_closures): void {

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

                      $this->deferred_checks[$method->getFQSEN()->__toString()] = static function (CodeBase $_) use ($warning_closures): void {

              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