Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lubiana opened this issue Apr 25, 2024 · 0 comments

Comments

@lubiana
Copy link

lubiana commented Apr 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant