Skip to content

[VersionBonding] Cap polyfill rules by explicitly picked withPhpSets() version - #8315

Merged
TomasVotruba merged 2 commits into
mainfrom
polyfill-ceiling-php-sets
Aug 8, 2026
Merged

[VersionBonding] Cap polyfill rules by explicitly picked withPhpSets() version#8315
TomasVotruba merged 2 commits into
mainfrom
polyfill-ceiling-php-sets

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

When a PHP version is picked explicitly, the SetList::PHP_POLYFILLS set is still loaded on top of the picked level sets. PhpVersionedFilter then activated any RelatedPolyfillInterface rule whose polyfill package sits in root composer.json, ignoring the picked version entirely.

So this config:

return RectorConfig::configure()
    ->withPhpSets(php82: true);

with symfony/polyfill-php83 required, still ran AddOverrideAttributeToOverriddenMethodsRector (and JsonValidateRector), producing PHP 8.3 code from a PHP 8.2 target:

 final class SomeClass extends ParentClass
 {
+    #[\Override]
     public function run()
     {
     }
 }

An explicitly picked version is an intended ceiling, so polyfilled rules above it are now skipped.

Unchanged behaviour when no version is picked — withPhpSets() resolving from composer.json keeps the full ahead-of-version polyfill activation, which is the point of the set:

// composer.json: "php": "^8.2", "symfony/polyfill-php83": "^1.0"
return RectorConfig::configure()
    ->withPhpSets();
// -> AddOverrideAttributeToOverriddenMethodsRector still active

Implementation

  • withPhpSets() stores the explicitly picked version, RectorConfigBuilder::__invoke() passes it as Option::POLYFILL_CEILING_PHP_VERSION.
  • PhpVersionedFilter skips the polyfill-package bypass when a ceiling is set, and gates RelatedPolyfillInterface rules on the ceiling instead of the project PHP version. The latter matters when composer.json allows a higher PHP than the picked set, e.g. "php": "^8.4" with withPhpSets(php82: true).

…) version

When a PHP version is explicitly picked, e.g. withPhpSets(php82: true),
the SetList::PHP_POLYFILLS set is still loaded. A rule bound to a higher
polyfill package, e.g. AddOverrideAttributeToOverriddenMethodsRector with
symfony/polyfill-php83, was then active regardless of the picked version.

The explicitly picked version is an intended ceiling, so polyfilled rules
above it are now skipped.
@TomasVotruba
TomasVotruba force-pushed the polyfill-ceiling-php-sets branch from 91eef62 to 77ef434 Compare August 7, 2026 23:00
@TomasVotruba
TomasVotruba force-pushed the polyfill-ceiling-php-sets branch from 926986e to ae8373d Compare August 8, 2026 04:30
@TomasVotruba
TomasVotruba merged commit 65cf2be into main Aug 8, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the polyfill-ceiling-php-sets branch August 8, 2026 04:33
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