Skip to content

[Config] Add ruleWithConfigurationComposerVersionBound() - #8244

Merged
TomasVotruba merged 1 commit into
mainfrom
rule-with-configuration-composer-version-bound
Jul 31, 2026
Merged

[Config] Add ruleWithConfigurationComposerVersionBound()#8244
TomasVotruba merged 1 commit into
mainfrom
rule-with-configuration-composer-version-bound

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

ComposerPackageConstraintInterface binds a whole rule to a package version. There is no way to bind a single configuration item - e.g. one AnnotationToAttribute pair - to the package version that introduced it.

This adds a version-bound variant of ruleWithConfiguration():

$rectorConfig->ruleWithConfigurationComposerVersionBound(
    AnnotationToAttributeRector::class,
    [new AnnotationToAttribute('test', 'PHPUnit\Framework\Attributes\Test')],
    'phpunit/phpunit',
    '>=10.0'
);

The configuration is registered only when the analysed project has a matching installed version. Since repeated ruleWithConfiguration() calls for the same rule class are merged, version-specific pairs stack on top of version-neutral ones across set files:

// version-neutral pairs
$rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
    new AnnotationToAttribute('someTag', SomeAttribute::class),
]);

// only on PHPUnit 11+
$rectorConfig->ruleWithConfigurationComposerVersionBound(
    AnnotationToAttributeRector::class,
    [new AnnotationToAttribute('someElevenTag', SomeElevenAttribute::class)],
    'phpunit/phpunit',
    '>=11.0'
);

Version resolving reuses InstalledPackageResolver, so it follows the same rules as ComposerPackageConstraintFilter, including the composer.json constraint priority added in #8242. An unresolvable version - package not installed - means the configuration is not registered, same as the existing filter.

…configuration bound to installed package version
@TomasVotruba

Copy link
Copy Markdown
Member Author

Ref #7877

@TomasVotruba
TomasVotruba merged commit 8ead5a5 into main Jul 31, 2026
65 checks passed
@TomasVotruba
TomasVotruba deleted the rule-with-configuration-composer-version-bound branch July 31, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant