kylekatarnls/business-time

View on GitHub
types.php

Summary

Maintainability
D
1 day
Test Coverage

Function parseMethodDoc has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

    private function parseMethodDoc(
        string $name,
        int $length,
        string $className,
        string $defaultClass,
Severity: Minor
Found in types.php - About 7 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 getScheduleDoc has 66 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getScheduleDoc($defaultClass, $source, $boot)
    {
        $methods = [];
        $source = str_replace('\\', '/', realpath($source));
        $sourceLength = strlen($source);
Severity: Major
Found in types.php - About 2 hrs to fix

    Function getScheduleDoc has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getScheduleDoc($defaultClass, $source, $boot)
        {
            $methods = [];
            $source = str_replace('\\', '/', realpath($source));
            $sourceLength = strlen($source);
    Severity: Minor
    Found in types.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 parseMethodDoc has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function parseMethodDoc(
            string $name,
            int $length,
            string $className,
            string $defaultClass,
    Severity: Minor
    Found in types.php - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                              if (preg_match('/^(public|protected)\s+function\s+(\S+)\(.*\)(\s*\{)?$/', trim($code[$i]), $match)) {
                                  break;
                              }
      Severity: Major
      Found in types.php - About 45 mins to fix

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

                string $name,
                int $length,
                string $className,
                string $defaultClass,
                array $code,
        Severity: Minor
        Found in types.php - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  for ($i = $length - 2; $i >= max(0, $length - 42); $i--) {
                                      $doc = $lines[$i].$doc;
          
                                      if (preg_match('/\s*\/\*{2,}\s*/', $lines[$i])) {
                                          $methodDocBlock = trim($doc) ?: $methodDocBlock;
          Severity: Major
          Found in types.php - About 45 mins to fix

            The method parseMethodDoc() has an NPath complexity of 219. The configured NPath complexity threshold is 200.
            Open

                private function parseMethodDoc(
                    string $name,
                    int $length,
                    string $className,
                    string $defaultClass,
            Severity: Minor
            Found in types.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 getScheduleDoc() has an NPath complexity of 1729. The configured NPath complexity threshold is 200.
            Open

                public function getScheduleDoc($defaultClass, $source, $boot)
                {
                    $methods = [];
                    $source = str_replace('\\', '/', realpath($source));
                    $sourceLength = strlen($source);
            Severity: Minor
            Found in types.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 parseMethodDoc() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
            Open

                private function parseMethodDoc(
                    string $name,
                    int $length,
                    string $className,
                    string $defaultClass,
            Severity: Minor
            Found in types.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 getScheduleDoc() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
            Open

                public function getScheduleDoc($defaultClass, $source, $boot)
                {
                    $methods = [];
                    $source = str_replace('\\', '/', realpath($source));
                    $sourceLength = strlen($source);
            Severity: Minor
            Found in types.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

            Refactor this function to reduce its Cognitive Complexity from 55 to the 15 allowed.
            Open

                private function parseMethodDoc(
            Severity: Critical
            Found in types.php by sonar-php

            Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

            See

            Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.
            Open

                public function getScheduleDoc($defaultClass, $source, $boot)
            Severity: Critical
            Found in types.php by sonar-php

            Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

            See

            Avoid using undefined variables such as '$files' which will lead to PHP notices.
            Open

                        $lines = $files[$file];
            Severity: Minor
            Found in types.php by phpmd

            UndefinedVariable

            Since: 2.8.0

            Detects when a variable is used that has not been defined before.

            Example

            class Foo
            {
                private function bar()
                {
                    // $message is undefined
                    echo $message;
                }
            }

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

            Avoid using undefined variables such as '$files' which will lead to PHP notices.
            Open

                        $methodDocBlock = $this->parseMethodDoc($name, $length, $className, $defaultClass, $code, $files)
            Severity: Minor
            Found in types.php by phpmd

            UndefinedVariable

            Since: 2.8.0

            Detects when a variable is used that has not been defined before.

            Example

            class Foo
            {
                private function bar()
                {
                    // $message is undefined
                    echo $message;
                }
            }

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

            Avoid using undefined variables such as '$files' which will lead to PHP notices.
            Open

                            $files[$file] = file($file);
            Severity: Minor
            Found in types.php by phpmd

            UndefinedVariable

            Since: 2.8.0

            Detects when a variable is used that has not been defined before.

            Example

            class Foo
            {
                private function bar()
                {
                    // $message is undefined
                    echo $message;
                }
            }

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

            Avoid using undefined variables such as '$files' which will lead to PHP notices.
            Open

                        if (!isset($files[$file])) {
            Severity: Minor
            Found in types.php by phpmd

            UndefinedVariable

            Since: 2.8.0

            Detects when a variable is used that has not been defined before.

            Example

            class Foo
            {
                private function bar()
                {
                    // $message is undefined
                    echo $message;
                }
            }

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

            Missing class import via use statement (line '130', column '39').
            Open

                                    $method = new ReflectionMethod($defaultClass, $name);
            Severity: Minor
            Found in types.php by phpmd

            MissingImport

            Since: 2.7.0

            Importing all external classes in a file through use statements makes them clearly visible.

            Example

            function make() {
                return new \stdClass();
            }

            Source http://phpmd.org/rules/cleancode.html#MissingImport

            Missing class import via use statement (line '128', column '39').
            Open

                                    $method = new ReflectionMethod($className, $name);
            Severity: Minor
            Found in types.php by phpmd

            MissingImport

            Since: 2.7.0

            Importing all external classes in a file through use statements makes them clearly visible.

            Example

            function make() {
                return new \stdClass();
            }

            Source http://phpmd.org/rules/cleancode.html#MissingImport

            Missing class import via use statement (line '41', column '33').
            Open

                            $function = new ReflectionFunction($closure);
            Severity: Minor
            Found in types.php by phpmd

            MissingImport

            Since: 2.7.0

            Importing all external classes in a file through use statements makes them clearly visible.

            Example

            function make() {
                return new \stdClass();
            }

            Source http://phpmd.org/rules/cleancode.html#MissingImport

            Refactor the code to avoid updating the loop counter "$i" within the loop body.
            Open

                                    for ($i = $length - 2; $i >= max(0, $length - 42); $i--) {
            Severity: Major
            Found in types.php by sonar-php

            A for loop stop condition should test the loop counter against an invariant value (i.e. one that is true at both the beginning and ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.

            Stop conditions that are not invariant are slightly less efficient, as well as being difficult to understand and maintain, and likely lead to the introduction of errors in the future.

            This rule tracks three types of non-invariant stop conditions:

            • When the loop counters are updated in the body of the for loop
            • When the stop condition depend upon a method call
            • When the stop condition depends on an object property, since such properties could change during the execution of the loop.

            Noncompliant Code Example

            for ($i = 0; $i < 10; $i++) {
              echo $i;
              if(condition) {
                $i = 20;
              }
            }
            

            Compliant Solution

            for ($i = 0; $i < 10; $i++) {
              echo $i;
            }
            
            

            See

            • MISRA C:2004, 13.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
            • MISRA C++:2008, 6-5-3 - The loop-counter shall not be modified within condition or statement.

            Refactor the code to avoid updating the loop counter "$i" within the loop body.
            Open

                                for ($i = $length - 1; $i >= 0; $i--) {
            Severity: Major
            Found in types.php by sonar-php

            A for loop stop condition should test the loop counter against an invariant value (i.e. one that is true at both the beginning and ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.

            Stop conditions that are not invariant are slightly less efficient, as well as being difficult to understand and maintain, and likely lead to the introduction of errors in the future.

            This rule tracks three types of non-invariant stop conditions:

            • When the loop counters are updated in the body of the for loop
            • When the stop condition depend upon a method call
            • When the stop condition depends on an object property, since such properties could change during the execution of the loop.

            Noncompliant Code Example

            for ($i = 0; $i < 10; $i++) {
              echo $i;
              if(condition) {
                $i = 20;
              }
            }
            

            Compliant Solution

            for ($i = 0; $i < 10; $i++) {
              echo $i;
            }
            
            

            See

            • MISRA C:2004, 13.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
            • MISRA C++:2008, 6-5-3 - The loop-counter shall not be modified within condition or statement.

            Refactor the code to avoid updating the loop counter "$i" within the loop body.
            Open

                                for ($i = $length - 1; $i >= 0; $i--) {
            Severity: Major
            Found in types.php by sonar-php

            A for loop stop condition should test the loop counter against an invariant value (i.e. one that is true at both the beginning and ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.

            Stop conditions that are not invariant are slightly less efficient, as well as being difficult to understand and maintain, and likely lead to the introduction of errors in the future.

            This rule tracks three types of non-invariant stop conditions:

            • When the loop counters are updated in the body of the for loop
            • When the stop condition depend upon a method call
            • When the stop condition depends on an object property, since such properties could change during the execution of the loop.

            Noncompliant Code Example

            for ($i = 0; $i < 10; $i++) {
              echo $i;
              if(condition) {
                $i = 20;
              }
            }
            

            Compliant Solution

            for ($i = 0; $i < 10; $i++) {
              echo $i;
            }
            
            

            See

            • MISRA C:2004, 13.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
            • MISRA C++:2008, 6-5-3 - The loop-counter shall not be modified within condition or statement.

            Refactor the code to avoid updating the loop counter "$i" within the loop body.
            Open

                                    for ($i = $length - 2; $i >= max(0, $length - 42); $i--) {
            Severity: Major
            Found in types.php by sonar-php

            A for loop stop condition should test the loop counter against an invariant value (i.e. one that is true at both the beginning and ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.

            Stop conditions that are not invariant are slightly less efficient, as well as being difficult to understand and maintain, and likely lead to the introduction of errors in the future.

            This rule tracks three types of non-invariant stop conditions:

            • When the loop counters are updated in the body of the for loop
            • When the stop condition depend upon a method call
            • When the stop condition depends on an object property, since such properties could change during the execution of the loop.

            Noncompliant Code Example

            for ($i = 0; $i < 10; $i++) {
              echo $i;
              if(condition) {
                $i = 20;
              }
            }
            

            Compliant Solution

            for ($i = 0; $i < 10; $i++) {
              echo $i;
            }
            
            

            See

            • MISRA C:2004, 13.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
            • MISRA C++:2008, 6-5-3 - The loop-counter shall not be modified within condition or statement.

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

                    $businessDaySourceLength = strlen($businessDaySource);
            Severity: Minor
            Found in types.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

            Each class must be in a namespace of at least one level (a top-level vendor name)
            Open

            final class TypeGenerator extends \Types\Generator
            Severity: Minor
            Found in types.php by phpcodesniffer

            A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 9 and the first side effect is on line 6.
            Open

            <?php
            Severity: Minor
            Found in types.php by phpcodesniffer

            Line exceeds 120 characters; contains 125 characters
            Open

            $contents = preg_replace('/(<autodoc([^>]*>))([\s\S]*)(<\/autodoc>)/', "$1\n *{{AUTODOC-CONTENT}}\n *</autodoc>", $contents);
            Severity: Minor
            Found in types.php by phpcodesniffer

            Line exceeds 120 characters; contains 125 characters
            Open

                                    if (preg_match('/^(public|protected)\s+function\s+(\S+)\(.*\)(\s*\{)?$/', trim($code[$i]), $match)) {
            Severity: Minor
            Found in types.php by phpcodesniffer

            There are no issues that match your filters.

            Category
            Status