Skip to content

Conversation

@calebdw
Copy link
Contributor

@calebdw calebdw commented Feb 3, 2026

Hello!

This PR introduces a new ComposerPackageConstraintInterface that 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 ComposerTriggeredSet

Rector already has ComposerTriggeredSet for composer-based filtering, but it serves a different purpose:

ComposerTriggeredSet ComposerPackageConstraintInterface
Operates on Sets (collections of rules) Individual rules
Purpose Auto-load upgrade sets based on installed version Skip rules if package constraint not satisfied
Version matching Caret (^) - targets specific major version Any semver constraint (>=, <, ^, ~, ranges, etc.)
Use case "Load Laravel 10 upgrade set if laravel/framework ^10 is installed" "Skip this rule if laravel/framework doesn't match constraint"
Cumulative No: each set targets a specific version range Depends on constraint used

ComposerTriggeredSet is designed for upgrade paths where you want different sets for different version jumps (9→10, 10→11, etc.). ComposerPackageConstraintInterface is for rules that should only run when a package satisfies a specific constraint (for example, apply to a version and all subsequent version).

Usage

<?php
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;

final class SomeLaravelRector extends AbstractRector implements ComposerPackageConstraintInterface
{
    public function provideComposerPackageConstraint(): ComposerPackageConstraint
    {
        // Min version
        return new ComposerPackageConstraint('laravel/framework', '>=10.0.0');
        
        // Or max version
        return new ComposerPackageConstraint('laravel/framework', '<10.0.0');
        
        // Or specific major
        return new ComposerPackageConstraint('laravel/framework', '^9.0');
        
        // Or range
        return new ComposerPackageConstraint('laravel/framework', '>=9.0 <11.0');
    }
}

Thanks!

This adds the ability to filter out rectors by composer package constraint.
@calebdw calebdw force-pushed the calebdw/push-ykxnnrtlxmkk branch from 747597b to 6bc2c5b Compare February 3, 2026 21:45
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

Successfully merging this pull request may close these issues.

1 participant