martin-helmich/typo3-typoscript-parser

View on GitHub
src/Parser/Printer/PrettyPrinter.php

Summary

Maintainability
A
3 hrs
Test Coverage
A
96%

Showing 92 of 92 total issues

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

    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

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

    The class PrettyPrinter has a coupling between objects value of 19. 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

    Avoid using static access to class 'Helmich\TypoScriptParser\Parser\Printer\PrettyPrinterConfiguration' in method '__construct'.
    Open

    $this->prettyPrinterConfiguration = $prettyPrinterConfiguration ?? PrettyPrinterConfiguration::create();
    Severity: Minor
    Found in src/Parser/Printer/PrettyPrinter.php by phpmd

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

    while (count($out) && $out[count($out) - 1] instanceof NopStatement) {
    array_pop($out);
    }
    Severity: Minor
    Found in src/Parser/Printer/PrettyPrinter.php by phpmd

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

    while (count($out) && $out[count($out) - 1] instanceof NopStatement) {
    array_pop($out);
    }
    Severity: Minor
    Found in src/Parser/Printer/PrettyPrinter.php by phpmd

    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 35 and the first side effect is on line 31.
    Open

    <?php

    Possible parse error: class missing opening or closing brace
    Open

    class PrettyPrinter implements ASTPrinterInterface

    DEFAULT statements must be defined using a colon
    Open

    default => "[end]",

    Possible parse error: class missing opening or closing brace
    Open

    class PrettyPrinter implements ASTPrinterInterface

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if ($nesting === 0) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    } elseif ($statement instanceof MultilineComment) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function getIndent(int $nesting): string

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if ($operator instanceof Copy) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    if ($statement->condition !== null) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    } elseif ($statement instanceof Delete) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function printNestedAssignment(OutputInterface $output, int $nesting, NestedAssignment $statement): void

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    switch ($this->prettyPrinterConfiguration->getConditionTermination()) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if ($statement->newSyntax) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function printAssignment(OutputInterface $output, Assignment $statement, string $indent): void

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    case PrettyPrinterConditionTermination::EnforceGlobal:

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if ($this->closeCondition($hasNext)) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private PrettyPrinterConfiguration $prettyPrinterConfiguration;

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    public function __construct(?PrettyPrinterConfiguration $prettyPrinterConfiguration = null)

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    } elseif ($statement instanceof Assignment) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    if ($statement instanceof NestedAssignment) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    } elseif ($statement instanceof BinaryObjectOperator) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    } elseif ($statement instanceof ConditionalStatement) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function printBinaryObjectOperator(OutputInterface $output, BinaryObjectOperator $operator, int $nesting): void

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if (str_contains($statement->value->value, "\n")) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    while (count($out) && $out[count($out) - 1] instanceof NopStatement) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function printFileIncludeStatement(OutputInterface $output, FileIncludeStatement $statement): void

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if ($statement->condition !== null) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function trimTrailingNoops(array $statements): array

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    } elseif ($operator instanceof Reference) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if ($statement instanceof FileIncludeStatement) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if ($this->prettyPrinterConfiguration->shouldIndentConditions()) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function printNopStatement(OutputInterface $output): void

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function closeCondition(bool $hasNext): bool

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    case PrettyPrinterConditionTermination::Keep:

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    } elseif ($statement instanceof IncludeStatement) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    } elseif ($statement instanceof Modification) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 8 spaces, found 20
    Open

    default => "[end]",

    Closing brace indented incorrectly; expected 4 spaces, found 0
    Open

    }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    } elseif ($statement instanceof Comment) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

    } elseif ($statement instanceof NopStatement) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    } elseif ($statement instanceof DirectoryIncludeStatement) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    } else {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Closing brace indented incorrectly; expected 8 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    public function printStatements(array $statements, OutputInterface $output): void

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    for ($i = 0; $i < $count; $i++) {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if ($statement->extensions !== null && $statement->extensions !== "") {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    public function setPrettyPrinterConfiguration(PrettyPrinterConfiguration $prettyPrinterConfiguration): void

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function printStatementList(array $statements, OutputInterface $output, int $nesting = 0): void

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function printIncludeStatement(OutputInterface $output, IncludeStatement $statement): void

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function printDirectoryIncludeStatement(OutputInterface $output, DirectoryIncludeStatement $statement): void

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function printConditionalStatement(OutputInterface $output, int $nesting, ConditionalStatement $statement, bool $hasNext = false): void

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    private function getConditionTerminatorStatement(ConditionalStatement $stmt): string

    Space before opening parenthesis of function call prohibited
    Open

    return match ($stmt->terminator) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if (count($statement->elseStatements) > 0) {

    Line indented incorrectly; expected 0 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 8
    Open

    if ($this->prettyPrinterConfiguration->shouldIncludeEmptyLineBreaks()) {
    Category
    Status