Skip to content

withComposerBased() fatals on Drupal projects: RectorPrefix…\DrupalRector\Set\DrupalSetList not found #9950

Closed

Description

@bbrala

Bug Report

When working on palantirnet/drupal-rector#419 I was chasing why it sometimes crashes and I couldnt work around some versions for the DrupalSetList. This was the analysis of it:


On a Drupal project with palantirnet/drupal-rector installed, the drupal toggle crashes at config load, before any file is processed:

[ERROR] Class "RectorPrefix202610\DrupalRector\Set\DrupalSetList" not found

Since 2.8.2, drupal/core is in ComposerBasedTriggerPackages, so a bare withComposerBased() turns on drupal: true automatically and hits the same crash.

Minimal PHP Code Causing Issue

<?php

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([__DIR__ . '/web/modules/custom'])
    ->withComposerBased(); // or ->withComposerBased(drupal: true)

Steps: Drupal 11 site, composer require --dev rector/rector:2.8.3 palantirnet/drupal-rector:dev-composer-based-set (the branch of palantirnet/drupal-rector#419 that adds DrupalSetList::COMPOSER_BASED), then run vendor/bin/rector process --dry-run.

Cause

src/Configuration/RectorConfigBuilder.php:

use DrupalRector\Set\DrupalSetList;                      // line 7
// ...
if ($drupal && class_exists('DrupalRector\Set\DrupalSetList') && constant('DrupalRector\Set\DrupalSetList::COMPOSER_BASED')) {
    $this->sets[] = DrupalSetList::COMPOSER_BASED;       // line 692
}

The string checks are left alone, but php-scoper prefixes the use import. scoper.php excludes #^Rector# (which is why RectorLaravel\… works) but not DrupalRector. Running from a rector-src checkout isn't scoped, so tests don't catch it.

Expected Behaviour

DrupalSetList::COMPOSER_BASED loads. Either fix works:

  • add '#^DrupalRector#' to exclude-namespaces in scoper.php, or
  • use $this->sets[] = constant('DrupalRector\Set\DrupalSetList::COMPOSER_BASED'); and drop the use import.

Activity

  1. samsonasik commented on Oct 30, 2026

    @samsonasik
    Member

    I see, the

    '#^Rector#',

    includes RectorLaravel, but not DrupalRector.

    Could you create PR for it? Thank you.

  2. samsonasik commented on Oct 30, 2026

    @samsonasik
    Member
  3. bbrala commented on Oct 30, 2026

    @bbrala
    Author

    <3 i love you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions