Skip to content

Resolve the composer-based set of extension packages in withComposerBased() - #8332

Merged
TomasVotruba merged 1 commit into
rectorphp:mainfrom
TomasVotruba:composer-based-extension-set-list
Aug 10, 2026
Merged

Resolve the composer-based set of extension packages in withComposerBased()#8332
TomasVotruba merged 1 commit into
rectorphp:mainfrom
TomasVotruba:composer-based-extension-set-list

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

withComposerBased(phpunit: true), doctrine:, twig: and symfony: load a single set in which every rule is bound to the installed package version on its own — the pattern ComposerPackageConstraintInterface deprecated SetProviderInterface and ComposerTriggeredSet in favour of.

The laravel: and drupal: toggles could not follow, because rector-src does not require those packages and so cannot import their set list class. They stayed on the deprecated set-group path, which means an extension that has migrated to a composer-based set has no way to be picked up by the very toggle meant to load it.

This resolves the extension's set list constant by name, so no dependency is needed:

private const array EXTENSION_COMPOSER_BASED_SET_LISTS = [
    SetGroup::LARAVEL => 'RectorLaravel\Set\LaravelSetList::COMPOSER_BASED',
    SetGroup::DRUPAL => 'DrupalRector\Set\DrupalSetList::COMPOSER_BASED',
];
-        foreach ($setMap as $setPath => $isEnabled) {
-            if ($isEnabled) {
-                $this->setGroups[] = $setPath;
+        foreach ($setMap as $setGroup => $isEnabled) {
+            if (! $isEnabled) {
+                continue;
             }
+
+            $setListConstant = self::EXTENSION_COMPOSER_BASED_SET_LISTS[$setGroup];
+            if (defined($setListConstant)) {
+                $setFilePath = constant($setListConstant);
+                Assert::string($setFilePath);
+
+                // single set, as every rule inside is bound to the installed package version on its own
+                $this->sets[] = $setFilePath;
+                continue;
+            }
+
+            // @deprecated fallback for extensions that still describe their sets as objects,
+            // instead of bonding the rules themselves
+            $this->setGroups[] = $setGroup;
         }

Constant defined → the set is loaded, exactly like the bundled packages'. Constant absent — extension not installed, or not migrated yet — → the set group is registered as before, so nothing changes for it. defined() autoloads the class and returns false rather than throwing when it does not exist.

palantirnet/drupal-rector has DrupalSetList::COMPOSER_BASED ready on a branch: a single generated set registering every rule with the exact drupal/core version its deprecation was introduced in, configurable ones through ruleWithConfigurationComposerVersionBound(). With this change withComposerBased(drupal: true) picks it up as soon as both are released, and rector composer-based reports the constraints.

…ased()

`withComposerBased(phpunit: true)` and friends load a single set in which every
rule is bound to the installed package version, which is what
`ComposerPackageConstraintInterface` deprecated `SetProviderInterface` and
`ComposerTriggeredSet` in favour of.

The `laravel:` and `drupal:` toggles could not follow, because rector-src does
not require those packages and cannot import their set list class. They were
left on the deprecated set-group path, so an extension that has already migrated
to a composer-based set has no way to be picked up by the toggle that is meant
to load it.

Resolve the extension's set list constant by name instead, so no dependency is
needed:

    private const array EXTENSION_COMPOSER_BASED_SET_LISTS = [
        SetGroup::LARAVEL => 'RectorLaravel\Set\LaravelSetList::COMPOSER_BASED',
        SetGroup::DRUPAL => 'DrupalRector\Set\DrupalSetList::COMPOSER_BASED',
    ];

When the constant is defined, the set is loaded like the bundled packages' ones.
When it is not — the extension is absent, or has not migrated yet — the set
group is registered exactly as before, so nothing changes for it.

palantirnet/drupal-rector has `DrupalSetList::COMPOSER_BASED` ready on a branch:
every rule is registered with the exact `drupal/core` version its deprecation
was introduced in, so `withComposerBased(drupal: true)` starts loading it as
soon as both are released.
@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 10, 2026 11:26
@TomasVotruba
TomasVotruba merged commit 1604041 into rectorphp:main Aug 10, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the composer-based-extension-set-list branch August 10, 2026 11:27
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