Skip to content

[Set] Allow a version constraint in ComposerTriggeredSet - #8245

Merged
TomasVotruba merged 2 commits into
mainfrom
composer-triggered-set-version-constraint
Jul 31, 2026
Merged

[Set] Allow a version constraint in ComposerTriggeredSet#8245
TomasVotruba merged 2 commits into
mainfrom
composer-triggered-set-version-constraint

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

ComposerTriggeredSet hardcodes '^' . $version, so a set can only be bound to a single major version:

return Semver::satisfies($package->getVersion(), '^' . $this->version);

That is fine for the per-version upgrade sets, but it makes it impossible to register a set that applies across majors - such as rector-phpunit's new composer-based.php, which should load for any installed PHPUnit and does its own per-rule version gating via ComposerPackageConstraintInterface and ruleWithConfigurationComposerVersionBound().

A bare version keeps behaving exactly as before; anything that is not a bare version is used as a constraint:

private function resolveVersionConstraint(): string
{
    if (Strings::match($this->version, self::BARE_VERSION_REGEX) !== null) {
        return '^' . $this->version;
    }

    return $this->version;
}

So both of these work:

// unchanged - matches ^10.0
new ComposerTriggeredSet(SetGroup::PHPUNIT, 'phpunit/phpunit', '10.0', __DIR__ . '/../config/sets/phpunit100.php'),

// new - matches any PHPUnit 10 and up
new ComposerTriggeredSet(SetGroup::PHPUNIT, 'phpunit/phpunit', '>=10.0', __DIR__ . '/../config/sets/composer-based.php'),

This is what lets withComposerBased(phpunit: true) pick up a package's composer-based set regardless of which PHPUnit major is installed, without registering the same set once per major version.

Backward compatible - every existing ComposerTriggeredSet in rector-src and the extension packages passes a bare version and keeps the ^ behaviour. Covered by ComposerTriggeredSetTest, including the bare version cases.

@TomasVotruba
TomasVotruba merged commit eac0fdc into main Jul 31, 2026
65 checks passed
@TomasVotruba
TomasVotruba deleted the composer-triggered-set-version-constraint branch July 31, 2026 19:39
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.

2 participants