File Parser.php
has 398 lines of code (exceeds 250 allowed). Consider refactoring.
<?php declare(strict_types=1);
namespace Helmich\TypoScriptParser\Parser;
use ArrayObject;
The class Parser has an overall complexity of 69 which is very high. The configured complexity threshold is 50.
class Parser implements ParserInterface
{
private TokenizerInterface $tokenizer;
private Builder $builder;
Method parseCondition
has 75 lines of code (exceeds 25 allowed). Consider refactoring.
private function parseCondition(ParserState $state): void
{
if ($state->context()->depth() !== 0) {
throw new ParseError(
'Found condition statement inside nested assignment.',
Function parseCondition
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
private function parseCondition(ParserState $state): void
{
if ($state->context()->depth() !== 0) {
throw new ParseError(
'Found condition statement inside nested assignment.',
Method parseToken
has 42 lines of code (exceeds 25 allowed). Consider refactoring.
private function parseToken(ParserState $state): void
{
switch ($state->token()->getType()) {
case TokenInterface::TYPE_OBJECT_IDENTIFIER:
$objectPath = $state->context()->append($state->token()->getValue());
Method parseNestedStatements
has 28 lines of code (exceeds 25 allowed). Consider refactoring.
private function parseNestedStatements(ParserState $state, ?int $startLine = null): void
{
$startLine = $startLine ?? $state->token()->getLine();
$statements = new ArrayObject();
$subContext = $state->withStatements($statements);
Method parseAssignment
has 27 lines of code (exceeds 25 allowed). Consider refactoring.
private function parseAssignment(ParserState $state): void
{
switch ($state->token(2)->getType()) {
case TokenInterface::TYPE_OBJECT_CONSTRUCTOR:
$state->statements()->append($this->builder->op()->objectCreation(
Function parseToken
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
private function parseToken(ParserState $state): void
{
switch ($state->token()->getType()) {
case TokenInterface::TYPE_OBJECT_IDENTIFIER:
$objectPath = $state->context()->append($state->token()->getValue());
Function parseNestedStatements
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
private function parseNestedStatements(ParserState $state, ?int $startLine = null): void
{
$startLine = $startLine ?? $state->token()->getLine();
$statements = new ArrayObject();
$subContext = $state->withStatements($statements);
Function parseIncludeOptionals
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
private function parseIncludeOptionals(string $optional, TokenInterface $token): array
{
if (!(preg_match_all('/((?<key>[a-z]+)="(?<value>[^"]*)\s*)+"/', $optional, $matches) > 0)) {
return [null, null];
}
Function parseValueOperation
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
private function parseValueOperation(ParserState $state): void
{
switch ($state->token(1)->getType()) {
case TokenInterface::TYPE_OPERATOR_ASSIGNMENT:
$this->parseAssignment($state);
Function parseTokens
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
public function parseTokens(array $tokens): array
{
$stream = (new TokenStream($tokens))->normalized();
$state = new ParserState($stream);
The method parseToken() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
private function parseToken(ParserState $state): void
{
switch ($state->token()->getType()) {
case TokenInterface::TYPE_OBJECT_IDENTIFIER:
$objectPath = $state->context()->append($state->token()->getValue());
The method parseCondition() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
private function parseCondition(ParserState $state): void
{
if ($state->context()->depth() !== 0) {
throw new ParseError(
'Found condition statement inside nested assignment.',
Missing class import via use statement (line '45', column '23').
throw new \InvalidArgumentException("could not open file '$stream'");
Avoid using Helmich\TypoScriptParser\Parser\count() function in for loops.
for ($i = 0; $i < count($matches[0]); $i++) {
$key = $matches['key'][$i];
$value = $matches['value'][$i];
switch ($key) {
Line indented incorrectly; expected at least 12 spaces, found 8
$node = $this->builder->op()->{$type}(
Line indented incorrectly; expected 8 spaces, found 12
default => "reference"
Space before opening parenthesis of function call prohibited
$type = match ($state->token(1)->getType()) {
There are no issues that match your filters.