Skip to content

LineLengthFixer crashes when using a fixer that removes empty parantheses after new keyword #199

@lubiana

Description

@lubiana

I ran into a problem with the symplify LineLengthFixer when I use a fixer that removes unneded parantheses on object creation as default parameter for class properties in constructor property promotion.
I checked the error with Slevomat NewWithoutParantheses sniff and php-cs-fixer NewWithParantheses configured to remove them.

I am not sure if this is an issue with ECS, the php-cs-fixer or the slevomat coding standard sniffs.

ecs.php

<?php declare(strict_types=1); use PhpCsFixer\Fixer\Operator\NewWithParenthesesFixer; use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; return ECSConfig::configure() ->withPaths([__DIR__ . '/Test.php']) ->withRules( [ LineLengthFixer::class, ] ) ->withConfiguredRule(NewWithParenthesesFixer::class, [ 'anonymous_class' => false, 'named_class' => false, ]) ;

Test.php

<?php declare(strict_types=1); final class Test { public function __construct( private DateTimeImmutable $dateTimeImmutable = new DateTimeImmutable() ) {} }

ecs output:

./vendor/bin/ecs --fix --debug [fixer] PhpCsFixer\Fixer\Operator\NewWithParenthesesFixer [fixer] Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer [ERROR] System error: "Fixing of "/app/Test.php" file by "Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer"   failed: Cannot access offset of type null on SplFixedArray in file   /app/vendor/symplify/easy-coding-standard/vendor/symplify/coding-standard/src/TokenRunner/Analyzer/FixerAnalyze  r/BlockFinder.php on line 43"Run ECS with "--debug" option and post the report here: https://github.com/symplify/symplify/issues/new in /app/Test.php:159

I am running EasyCodingStandard 12.1.14 and php 8.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions