src/Phan/Analysis/AssignOperatorAnalysisVisitor.php

Summary

Maintainability
F
3 days
Test Coverage

File AssignOperatorAnalysisVisitor.php has 583 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Phan\Analysis;
Severity: Major
Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 1 day to fix

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

    class AssignOperatorAnalysisVisitor extends FlagVisitorImplementation
    {
    
        /**
         * @var CodeBase The code base within which we're operating

    The class AssignOperatorAnalysisVisitor has 16 public methods. Consider refactoring AssignOperatorAnalysisVisitor to keep number of public methods under 10.
    Open

    class AssignOperatorAnalysisVisitor extends FlagVisitorImplementation
    {
    
        /**
         * @var CodeBase The code base within which we're operating

    TooManyPublicMethods

    Since: 0.1

    A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

    By default it ignores methods starting with 'get' or 'set'.

    Example

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

    The class AssignOperatorAnalysisVisitor has 27 non-getter- and setter-methods. Consider refactoring AssignOperatorAnalysisVisitor to keep number of methods under 25.
    Open

    class AssignOperatorAnalysisVisitor extends FlagVisitorImplementation
    {
    
        /**
         * @var CodeBase The code base within which we're operating

    TooManyMethods

    Since: 0.1

    A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

    By default it ignores methods starting with 'get' or 'set'.

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

    Example

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

    Method visitBinaryAdd has 81 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function visitBinaryAdd(Node $node): Context
        {
            return $this->updateTargetWithType($node, function (UnionType $left) use ($node): UnionType {
                $code_base = $this->code_base;
                $context = $this->context;
    Severity: Major
    Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 3 hrs to fix

      AssignOperatorAnalysisVisitor has 27 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class AssignOperatorAnalysisVisitor extends FlagVisitorImplementation
      {
      
          /**
           * @var CodeBase The code base within which we're operating
      Severity: Minor
      Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 3 hrs to fix

        Function updateTargetDimWithType has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            private function updateTargetDimWithType(Node $assign_op_node, Closure $get_type): Context
            {
                $node = $assign_op_node->children['var'];
                if (!$node instanceof Node) {
                    // Should be impossible as currently called, but warn anyway.
        Severity: Minor
        Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.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 updateTargetDimWithType has 71 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function updateTargetDimWithType(Node $assign_op_node, Closure $get_type): Context
            {
                $node = $assign_op_node->children['var'];
                if (!$node instanceof Node) {
                    // Should be impossible as currently called, but warn anyway.
        Severity: Major
        Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 2 hrs to fix

          Method analyzeNumericArithmeticOp has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function analyzeNumericArithmeticOp(Node $node, bool $combination_is_int): Context
              {
                  return $this->updateTargetWithType($node, function (UnionType $left) use ($node, $combination_is_int): UnionType {
                      $code_base = $this->code_base;
                      $context = $this->context;
          Severity: Minor
          Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 1 hr to fix

            Method updateTargetVariableWithType has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function updateTargetVariableWithType(Node $node, Closure $get_type): Context
                {
                    try {
                        $variable_name = (new ContextNode(
                            $this->code_base,
            Severity: Minor
            Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 1 hr to fix

              Method updateTargetPropWithType has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function updateTargetPropWithType(Node $assign_op_node, Closure $get_type): Context
                  {
                      $node = $assign_op_node->children['var'];
                      if (!($node instanceof Node)) {
                          $this->emitIssue(
              Severity: Minor
              Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 1 hr to fix

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

                        Node $node,
                        Closure $is_valid_type,
                        UnionType $left,
                        UnionType $right,
                        string $left_issue_type,
                Severity: Minor
                Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if ($this->context->isInGlobalScope()) {
                                              return $this->updateTargetWithType($assign_op_node, $get_type);
                                          }
                  Severity: Major
                  Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 45 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return $this->context->withScopeVariable($variable);
                    Severity: Major
                    Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return $this->context;
                      Severity: Major
                      Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return (new AssignmentVisitor(
                                    $this->code_base,
                                    $this->context,
                                    $node,
                                    $new_type
                        Severity: Major
                        Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.php - About 30 mins to fix

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

                              private function warnAboutInvalidUnionType(
                                  Node $node,
                                  Closure $is_valid_type,
                                  UnionType $left,
                                  UnionType $right,
                          Severity: Minor
                          Found in src/Phan/Analysis/AssignOperatorAnalysisVisitor.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 visitBinaryAdd() has 103 lines of code. Current threshold is set to 100. Avoid really long methods.
                          Open

                              public function visitBinaryAdd(Node $node): Context
                              {
                                  return $this->updateTargetWithType($node, function (UnionType $left) use ($node): UnionType {
                                      $code_base = $this->code_base;
                                      $context = $this->context;

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

                              private function updateTargetDimWithType(Node $assign_op_node, Closure $get_type): Context
                              {
                                  $node = $assign_op_node->children['var'];
                                  if (!$node instanceof Node) {
                                      // Should be impossible as currently called, but warn anyway.

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

                              private function analyzeBitwiseOperation(Node $node): Context
                              {
                                  return $this->updateTargetWithType($node, function (UnionType $left_type) use ($node): UnionType {
                                      // TODO: Warn about invalid left and right-hand sides here and in BinaryOperatorFlagVisitor.
                                      // TODO: Return real types if both sides are real types.

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

                              public function visitBinaryAdd(Node $node): Context
                              {
                                  return $this->updateTargetWithType($node, function (UnionType $left) use ($node): UnionType {
                                      $code_base = $this->code_base;
                                      $context = $this->context;

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

                              private function analyzeNumericArithmeticOp(Node $node, bool $combination_is_int): Context
                              {
                                  return $this->updateTargetWithType($node, function (UnionType $left) use ($node, $combination_is_int): UnionType {
                                      $code_base = $this->code_base;
                                      $context = $this->context;

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

                          class AssignOperatorAnalysisVisitor extends FlagVisitorImplementation
                          {
                          
                              /**
                               * @var CodeBase The code base within which we're operating

                          CouplingBetweenObjects

                          Since: 1.1.0

                          A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                          Example

                          class Foo {
                              /**
                               * @var \foo\bar\X
                               */
                              private $x = null;
                          
                              /**
                               * @var \foo\bar\Y
                               */
                              private $y = null;
                          
                              /**
                               * @var \foo\bar\Z
                               */
                              private $z = null;
                          
                              public function setFoo(\Foo $foo) {}
                              public function setBar(\Bar $bar) {}
                              public function setBaz(\Baz $baz) {}
                          
                              /**
                               * @return \SplObjectStorage
                               * @throws \OutOfRangeException
                               * @throws \InvalidArgumentException
                               * @throws \ErrorException
                               */
                              public function process(\Iterator $it) {}
                          
                              // ...
                          }

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

                          There are no issues that match your filters.

                          Category
                          Status