feat: add ComposerPackageConstraintInterface - #7877
Conversation
747597b to
6bc2c5b
Compare
This adds the ability to filter out rectors by composer package constraint.
6bc2c5b to
ed459b4
Compare
|
This looks like much lightweight than the cumbersome sets provider approach. Love it 🥰 Let's give it a go and test it. Thanks |
|
I just noticed we have this feature in Rector... such an underrated power. I'll have to tell my agents about it to flip all the Symfony/PHPUnit/Rector sets to this and just let Rector load the right rules automatically :) |
|
Yes! In my opinion, this kind of makes the composer sets obsolete. I've been meaning to update rector-laravel but haven't had time yet |
|
Yeah, I wanted to make this happen, but was affraid of huge cognitive load to solve these. My 1st trial to verify this works end-to-end is to upgrade to PHPUnit 11 and let Rector 1-shot the upgrade with 0 deprecations repoted by PHPUnit. (Watch live force pushes here on @mautic mautic/mautic#16891) Single rule are easy to do now, but I've struggled with configured ones - e.g. some PHP 8 attributes were available on PHPUnit 10, some on PHPUnit 11 etc. So I made new config method to handle package + custom rules + version: #8244 |
…traintInterface A set triggered on a single major version has to be repeated for every version an upgrade passes through. A rule bonded with ComposerPackageConstraintInterface, added in #7877, states the exact package version its target API is available from and applies from there upwards, so one set covers every upgrade path. rectorphp/rector-symfony#1010 and rectorphp/rector-phpunit#758 moved both extensions over, leaving Twig as the only remaining user. The internal resolving of the class is kept working and ignored in phpstan.neon until that lands too.
Hello!
This PR introduces a new
ComposerPackageConstraintInterfacethat allows individual Rector rules to specify a composer package constraint. Rules implementing this interface will be automatically skipped if the required package is not installed or does not satisfy the specified constraint.Motivation
This is analogous to
MinPhpVersionInterface(which skips rules based on PHP version) but for composer packages. This is particularly useful for framework-specific rules (e.g., Laravel, Symfony) where certain rules only make sense for specific package versions.Comparison with
ComposerTriggeredSetRector already has
ComposerTriggeredSetfor composer-based filtering, but it serves a different purpose:ComposerTriggeredSetComposerPackageConstraintInterface^) - targets specific major version>=,<,^,~, ranges, etc.)ComposerTriggeredSetis designed for upgrade paths where you want different sets for different version jumps (9→10, 10→11, etc.).ComposerPackageConstraintInterfaceis for rules that should only run when a package satisfies a specific constraint (for example, apply to a version and all subsequent version).Usage
Thanks!