martin-helmich/typo3-typoscript-parser

View on GitHub
src/Parser/Parser.php

Summary

Maintainability
D
2 days
Test Coverage
A
97%

File Parser.php has 389 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php declare(strict_types=1);

namespace Helmich\TypoScriptParser\Parser;

use ArrayObject;
Severity: Minor
Found in src/Parser/Parser.php - About 5 hrs to fix

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

    class Parser implements ParserInterface
    {
        private TokenizerInterface $tokenizer;
    
        private Builder $builder;
    Severity: Minor
    Found in src/Parser/Parser.php by phpmd

    Method parseCondition has 71 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function parseCondition(ParserState $state): void
        {
            if ($state->context()->depth() !== 0) {
                throw new ParseError(
                    'Found condition statement inside nested assignment.',
    Severity: Major
    Found in src/Parser/Parser.php - About 2 hrs to fix

      Function parseCondition has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          private function parseCondition(ParserState $state): void
          {
              if ($state->context()->depth() !== 0) {
                  throw new ParseError(
                      'Found condition statement inside nested assignment.',
      Severity: Minor
      Found in src/Parser/Parser.php - About 1 hr to fix

      Cognitive Complexity

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

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

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

      Further reading

      Method parseToken has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function parseToken(ParserState $state): void
          {
              switch ($state->token()->getType()) {
                  case TokenInterface::TYPE_OBJECT_IDENTIFIER:
                      $objectPath = $state->context()->append($state->token()->getValue());
      Severity: Minor
      Found in src/Parser/Parser.php - About 1 hr to fix

        Method parseNestedStatements has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function parseNestedStatements(ParserState $state, ?int $startLine = null): void
            {
                $startLine  = $startLine ?? $state->token()->getLine();
                $statements = new ArrayObject();
                $subContext = $state->withStatements($statements);
        Severity: Minor
        Found in src/Parser/Parser.php - About 1 hr to fix

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

              private function parseAssignment(ParserState $state): void
              {
                  switch ($state->token(2)->getType()) {
                      case TokenInterface::TYPE_OBJECT_CONSTRUCTOR:
                          $state->statements()->append($this->builder->op()->objectCreation(
          Severity: Minor
          Found in src/Parser/Parser.php - About 1 hr to fix

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

                private function parseToken(ParserState $state): void
                {
                    switch ($state->token()->getType()) {
                        case TokenInterface::TYPE_OBJECT_IDENTIFIER:
                            $objectPath = $state->context()->append($state->token()->getValue());
            Severity: Minor
            Found in src/Parser/Parser.php - About 55 mins to fix

            Cognitive Complexity

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

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

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

            Further reading

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

                private function parseNestedStatements(ParserState $state, ?int $startLine = null): void
                {
                    $startLine  = $startLine ?? $state->token()->getLine();
                    $statements = new ArrayObject();
                    $subContext = $state->withStatements($statements);
            Severity: Minor
            Found in src/Parser/Parser.php - About 55 mins to fix

            Cognitive Complexity

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

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

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

            Further reading

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

                private function parseIncludeOptionals(string $optional, TokenInterface $token): array
                {
                    if (!(preg_match_all('/((?<key>[a-z]+)="(?<value>[^"]*)\s*)+"/', $optional, $matches) > 0)) {
                        return [null, null];
                    }
            Severity: Minor
            Found in src/Parser/Parser.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 parseTokens has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function parseTokens(array $tokens): array
                {
                    $stream = (new TokenStream($tokens))->normalized();
                    $state  = new ParserState($stream);
            
            
            Severity: Minor
            Found in src/Parser/Parser.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

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

                private function parseValueOperation(ParserState $state): void
                {
                    switch ($state->token(1)->getType()) {
                        case TokenInterface::TYPE_OPERATOR_ASSIGNMENT:
                            $this->parseAssignment($state);
            Severity: Minor
            Found in src/Parser/Parser.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 parseToken() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
            Open

                private function parseToken(ParserState $state): void
                {
                    switch ($state->token()->getType()) {
                        case TokenInterface::TYPE_OBJECT_IDENTIFIER:
                            $objectPath = $state->context()->append($state->token()->getValue());
            Severity: Minor
            Found in src/Parser/Parser.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

            Missing class import via use statement (line '42', column '23').
            Open

                        throw new \InvalidArgumentException("could not open file '$stream'");
            Severity: Minor
            Found in src/Parser/Parser.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

            Avoid using Helmich\TypoScriptParser\Parser\count() function in for loops.
            Open

                    for ($i = 0; $i < count($matches[0]); $i++) {
                        $key   = $matches['key'][$i];
                        $value = $matches['value'][$i];
            
                        switch ($key) {
            Severity: Minor
            Found in src/Parser/Parser.php by phpmd

            CountInLoopExpression

            Since: 2.7.0

            Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

            Example

            class Foo {
            
              public function bar()
              {
                $array = array();
            
                for ($i = 0; count($array); $i++) {
                  // ...
                }
              }
            }

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

            There are no issues that match your filters.

            Category
            Status