martin-helmich/typo3-typoscript-parser

View on GitHub
src/Parser/Parser.php

Summary

Maintainability
D
2 days
Test Coverage
A
97%

Showing 19 of 19 total issues

File Parser.php has 398 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 75 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 3 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

      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 28 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

            Function parseNestedStatements has a Cognitive Complexity of 8 (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 45 mins to fix

            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

            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

            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

            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

            The method parseCondition() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
            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 by phpmd

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

            throw new \InvalidArgumentException("could not open file '$stream'");
            Severity: Minor
            Found in src/Parser/Parser.php by phpmd

            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

            Line indented incorrectly; expected at least 12 spaces, found 8
            Open

            $node = $this->builder->op()->{$type}(
            Severity: Minor
            Found in src/Parser/Parser.php by phpcodesniffer

            Line indented incorrectly; expected 8 spaces, found 12
            Open

            default => "reference"
            Severity: Minor
            Found in src/Parser/Parser.php by phpcodesniffer

            Space before opening parenthesis of function call prohibited
            Open

            $type = match ($state->token(1)->getType()) {
            Severity: Minor
            Found in src/Parser/Parser.php by phpcodesniffer
            Category
            Status