martin-helmich/typo3-typoscript-parser

View on GitHub

Showing 49 of 49 total issues

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 TokenStream has 11 public methods. Consider refactoring TokenStream to keep number of public methods under 10.
    Open

    class TokenStream implements Iterator, ArrayAccess
    {
        /**
         * @var TokenInterface[]
         */
    Severity: Minor
    Found in src/Parser/TokenStream.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 Builder has 11 public methods. Consider refactoring Builder to keep number of public methods under 10.
    Open

    class Builder
    {
        private Operator\Builder $operatorBuilder;
    
        /**
    Severity: Minor
    Found in src/Parser/AST/Builder.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 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 tokenizeString has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function tokenizeString(string $inputString): array
          {
              $inputString = $this->preprocessor->preprocess($inputString);
      
              $tokens = new TokenStreamBuilder();
      Severity: Minor
      Found in src/Tokenizer/Tokenizer.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

      File Tokenizer.php has 258 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      declare(strict_types=1);
      
      namespace Helmich\TypoScriptParser\Tokenizer;
      Severity: Minor
      Found in src/Tokenizer/Tokenizer.php - About 2 hrs to fix

        Method tokenizeBinaryObjectOperation has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function tokenizeBinaryObjectOperation(TokenStreamBuilder $tokens, array $matches, int $currentLine): void
            {
                $tokens->append(
                    $this->getTokenTypeForBinaryOperator($matches[3]),
                    $matches[3],
        Severity: Minor
        Found in src/Tokenizer/Tokenizer.php - About 1 hr to fix

          Method tokenizeString has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function tokenizeString(string $inputString): array
              {
                  $inputString = $this->preprocessor->preprocess($inputString);
          
                  $tokens = new TokenStreamBuilder();
          Severity: Minor
          Found in src/Tokenizer/Tokenizer.php - About 1 hr 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 printStatementList has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function printStatementList(array $statements, OutputInterface $output, int $nesting = 0): void
                {
                    if ($nesting === 0) {
                        $statements = $this->trimTrailingNoops($statements);
                    }
            Severity: Minor
            Found in src/Parser/Printer/PrettyPrinter.php - About 1 hr to fix

              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

                Function printStatementList has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function printStatementList(array $statements, OutputInterface $output, int $nesting = 0): void
                    {
                        if ($nesting === 0) {
                            $statements = $this->trimTrailingNoops($statements);
                        }
                Severity: Minor
                Found in src/Parser/Printer/PrettyPrinter.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 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 tokenizeBinaryObjectOperation has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function tokenizeBinaryObjectOperation(TokenStreamBuilder $tokens, array $matches, int $currentLine): void
                        {
                            $tokens->append(
                                $this->getTokenTypeForBinaryOperator($matches[3]),
                                $matches[3],
                    Severity: Minor
                    Found in src/Tokenizer/Tokenizer.php - About 45 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 class Tokenizer has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
                    Open

                    class Tokenizer implements TokenizerInterface
                    {
                        const OBJECT_ACCESSOR = '((?:\.)|(?:[a-zA-Z0-9_\-\\\\:\$\{\}/]+(?:\.[a-zA-Z0-9_\-\\\\:\$\{\}/]*)*))';
                    
                        const TOKEN_WHITESPACE = ',^[ \t\n]+,s';
                    Severity: Minor
                    Found in src/Tokenizer/Tokenizer.php by phpmd

                    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

                    The class PrettyPrinter has a coupling between objects value of 17. Consider to reduce the number of dependencies under 13.
                    Open

                    class PrettyPrinter implements ASTPrinterInterface
                    {
                        private PrettyPrinterConfiguration $prettyPrinterConfiguration;
                    
                        public function __construct(PrettyPrinterConfiguration $prettyPrinterConfiguration = null)
                    Severity: Minor
                    Found in src/Parser/Printer/PrettyPrinter.php by phpmd

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language