Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell Rector to not apply any changes except those related to PHP compatibility?

Tags:

php

rector

As title states, I'm only interested in issues that can affect PHP compatibility, but it keeps changing array() into [] etc. Any tips?

My rector.php config so far:

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->rules([]);
    $rectorConfig->sets([LevelSetList::UP_TO_PHP_82]);
    $rectorConfig->paths([
        // my paths
    ]);
};

Looks like the only way is to walk through the rules one by one and add them in the skip list? For example

    ->withSkip([
        LongArrayToShortArrayRector::class,
        // ... more rules that don't break compatibility actually
    ])

Sadly, lots of rules are related to best practice and using latest features, rather than what breaks PHP, polluting the needed changes with the recommended changes.

like image 861
Olle Härstedt Avatar asked Oct 20 '25 11:10

Olle Härstedt


1 Answers

This did it for me

->withSkip([
        Rector\Php54\Rector\Array_\LongArrayToShortArrayRector::class,
    ])      

This helped me find rules

vendor/bin/rector list-rules
like image 102
Chris Muench Avatar answered Oct 22 '25 23:10

Chris Muench



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!