marcelog/PAGI

View on GitHub
src/PAGI/Node/Node.php

Summary

Maintainability
F
4 days
Test Coverage

File Node.php has 572 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * A node, used to get input from the user, validate it, play prompt messages,
 * etc.
 *
Severity: Major
Found in src/PAGI/Node/Node.php - About 1 day to fix

    Node has 66 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Node
    {
        /**
         * Any of the available DTMF digits in a classic telephone.
         * @var string
    Severity: Major
    Found in src/PAGI/Node/Node.php - About 1 day to fix

      Function run has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          public function run()
          {
              $this->inputAttemptsUsed = 0;
              if ($this->executeBeforeRun !== null) {
                  $callback = $this->executeBeforeRun;
      Severity: Minor
      Found in src/PAGI/Node/Node.php - About 4 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Function doInput has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function doInput()
          {
              /* @var $result IReadResult */
              $this->resetInput();
              $this->inputAttemptsUsed++;
      Severity: Minor
      Found in src/PAGI/Node/Node.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

      The class Node has 37 public methods. Consider refactoring Node to keep number of public methods under 10.
      Open

      class Node
      {
          /**
           * Any of the available DTMF digits in a classic telephone.
           * @var string
      Severity: Minor
      Found in src/PAGI/Node/Node.php by phpmd

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

      class Node
      {
          /**
           * Any of the available DTMF digits in a classic telephone.
           * @var string
      Severity: Minor
      Found in src/PAGI/Node/Node.php by phpmd

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

      class Node
      {
          /**
           * Any of the available DTMF digits in a classic telephone.
           * @var string
      Severity: Minor
      Found in src/PAGI/Node/Node.php by phpmd

      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 run has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function run()
          {
              $this->inputAttemptsUsed = 0;
              if ($this->executeBeforeRun !== null) {
                  $callback = $this->executeBeforeRun;
      Severity: Major
      Found in src/PAGI/Node/Node.php - About 2 hrs to fix

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

            protected function doInput()
            {
                /* @var $result IReadResult */
                $this->resetInput();
                $this->inputAttemptsUsed++;
        Severity: Minor
        Found in src/PAGI/Node/Node.php - About 1 hr to fix

          The class Node has 29 fields. Consider redesigning Node to keep the number of fields under 15.
          Open

          class Node
          {
              /**
               * Any of the available DTMF digits in a classic telephone.
               * @var string
          Severity: Minor
          Found in src/PAGI/Node/Node.php by phpmd

          TooManyFields

          Since: 0.1

          Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

          Example

          class Person {
             protected $one;
             private $two;
             private $three;
             [... many more fields ...]
          }

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

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

              public function validate()
              {
                  foreach ($this->inputValidations as $name => $data) {
                      $validator = $data['callback'];
                      $result = $validator($this);
          Severity: Minor
          Found in src/PAGI/Node/Node.php - About 1 hr to fix

          Cognitive Complexity

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

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

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

          Further reading

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

          class Node
          {
              /**
               * Any of the available DTMF digits in a classic telephone.
               * @var string
          Severity: Minor
          Found in src/PAGI/Node/Node.php by phpmd

          ExcessivePublicCount

          Since: 0.1

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

          Example

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

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

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

              protected function callClientMethods($methods, $stopWhen = null)
              {
                  $result = null;
                  foreach ($methods as $callInfo) {
                      foreach ($callInfo as $name => $arguments) {
          Severity: Minor
          Found in src/PAGI/Node/Node.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

          Avoid too many return statements within this method.
          Open

                          return "max valid input attempts reached";
          Severity: Major
          Found in src/PAGI/Node/Node.php - About 30 mins to fix

            The method doInput() has an NPath complexity of 665. The configured NPath complexity threshold is 200.
            Open

                protected function doInput()
                {
                    /* @var $result IReadResult */
                    $this->resetInput();
                    $this->inputAttemptsUsed++;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

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

                public function run()
                {
                    $this->inputAttemptsUsed = 0;
                    if ($this->executeBeforeRun !== null) {
                        $callback = $this->executeBeforeRun;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            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 class Node has 1325 lines of code. Current threshold is 1000. Avoid really long classes.
            Open

            class Node
            {
                /**
                 * Any of the available DTMF digits in a classic telephone.
                 * @var string
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

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

                protected function doInput()
                {
                    /* @var $result IReadResult */
                    $this->resetInput();
                    $this->inputAttemptsUsed++;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

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

                public function run()
                {
                    $this->inputAttemptsUsed = 0;
                    if ($this->executeBeforeRun !== null) {
                        $callback = $this->executeBeforeRun;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            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 validate uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                            } else {
                                $this->logDebug("Ignoring validation sound: " . print_r($onError, true));
                            }
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            The method doInput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                    } else {
                        $result = $this->playPromptMessages();
                        if ($result !== null) {
                            $this->acceptInput($result->getDigits());
                        }
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            The method resetInput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                    } else {
                        $this->state = self::STATE_TIMEOUT;
                    }
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            Avoid unused local variables such as '$result'.
            Open

                    $result = $this->playPrePromptMessages();
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            UnusedLocalVariable

            Since: 0.2

            Detects when a local variable is declared and/or assigned, but not used.

            Example

            class Foo {
                public function doSomething()
                {
                    $i = 5; // Unused
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

            Avoid excessively long variable names like $executeAfterFailedValidation. Keep variable name length under 20.
            Open

                private $executeAfterFailedValidation = null;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

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

            Avoid excessively long variable names like $validatorsInformation. Keep variable name length under 20.
            Open

                public function loadValidatorsFrom(array $validatorsInformation)
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

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

            Avoid excessively long variable names like $totalAttemptsForInput. Keep variable name length under 20.
            Open

                private $totalAttemptsForInput = 1;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

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

            Avoid excessively long variable names like $onMaxValidInputAttempts. Keep variable name length under 20.
            Open

                private $onMaxValidInputAttempts = null;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

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

            Avoid excessively long variable names like $playOnNoInputInLastAttempt. Keep variable name length under 20.
            Open

                private $playOnNoInputInLastAttempt = false;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

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

            Avoid excessively long variable names like $promptsCanBeInterrupted. Keep variable name length under 20.
            Open

                private $promptsCanBeInterrupted = true;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

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

            Avoid excessively long variable names like $cancelWithInputRetriesInput. Keep variable name length under 20.
            Open

                private $cancelWithInputRetriesInput = false;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

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

            Avoid excessively long variable names like $prePromptMessagesInterruptable. Keep variable name length under 20.
            Open

                private $prePromptMessagesInterruptable = true;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

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

            Avoid excessively long variable names like $acceptPrePromptInputAsInput. Keep variable name length under 20.
            Open

                private $acceptPrePromptInputAsInput = true;
            Severity: Minor
            Found in src/PAGI/Node/Node.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

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

            There are no issues that match your filters.

            Category
            Status