diff --git a/composer.json b/composer.json index 172542b1..401dbea4 100644 --- a/composer.json +++ b/composer.json @@ -75,12 +75,7 @@ "minimum-stability": "dev", "prefer-stable": true, "extra": { - "enable-patching": true, - "rector": { - "includes": [ - "config/extension.php" - ] - } + "enable-patching": true }, "require-dev": { "php": "^8.2", diff --git a/config/drupal-bootstrap.php b/config/drupal-bootstrap.php index ba5a930f..f5b24bb3 100644 --- a/config/drupal-bootstrap.php +++ b/config/drupal-bootstrap.php @@ -34,4 +34,40 @@ // need them can re-register this singleton in its own rector.php.) $rectorConfig->singleton(DrupalRectorSettings::class, fn () => (new DrupalRectorSettings()) ->disableBackwardCompatibility()); + + // Drupal executes PHP from several non-.php extensions. + $rectorConfig->fileExtensions(['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); + + // upgrade_status ships intentionally broken test modules. + $rectorConfig->skip(['*/upgrade_status/tests/modules/*']); + + // Autoloading and phpstan-drupal only make sense when Drupal is actually + // present. Bail out otherwise — DrupalFinderComposerRuntime::getDrupalRoot() + // calls Composer\InstalledVersions::getInstallPath('drupal/core'), which + // THROWS (not returns null) when the package is not installed, so this must + // be guarded before the lookup. + if (! \Composer\InstalledVersions::isInstalled('drupal/core')) { + return; + } + + $drupalFinder = new \DrupalFinder\DrupalFinderComposerRuntime(); + + $drupalRoot = $drupalFinder->getDrupalRoot(); + if (is_string($drupalRoot) && $drupalRoot !== '') { + $rectorConfig->autoloadPaths([ + $drupalRoot.'/core', + $drupalRoot.'/modules', + $drupalRoot.'/profiles', + $drupalRoot.'/themes', + ]); + } + + // phpstan-drupal lives in the analysed project's vendor dir, not ours. + $vendorDir = $drupalFinder->getVendorDir(); + if (is_string($vendorDir) && $vendorDir !== '') { + $phpstanDrupalExtension = $vendorDir.'/mglaman/phpstan-drupal/extension.neon'; + if (file_exists($phpstanDrupalExtension)) { + $rectorConfig->phpstanConfigs([$phpstanDrupalExtension]); + } + } }; diff --git a/config/extension.php b/config/extension.php deleted file mode 100644 index b84158a0..00000000 --- a/config/extension.php +++ /dev/null @@ -1,67 +0,0 @@ - this file -> the project's - * rector.php. Because the project's config is applied last it always wins: - * fileExtensions() and autoloadPaths() use "last call wins" semantics, while - * skip() and phpstanConfigs() are additive. So everything here is a default the - * project can still override. - * - * Imported via $rectorConfig->import(), hence the RectorConfig closure form - * rather than RectorConfig::configure(). - * - * NOTE: this deliberately does NOT register config/drupal-phpunit-bootstrap-file.php. - * That bootstrap throws when it cannot detect a Drupal installation, which would - * break Rector in any non-Drupal context. The bootstrap is registered by the - * deprecation sets instead (see \DrupalRector\Set\DrupalSetProvider and the - * *-all-deprecations sets), which only run against an actual Drupal codebase. - */ -return static function (RectorConfig $rectorConfig): void { - // Drupal executes PHP from several non-.php extensions. - $rectorConfig->fileExtensions(['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); - - // upgrade_status ships intentionally broken test modules. - $rectorConfig->skip(['*/upgrade_status/tests/modules/*']); - - // Autoloading and phpstan-drupal only make sense when Drupal is actually - // present. Bail out otherwise — DrupalFinderComposerRuntime::getDrupalRoot() - // calls Composer\InstalledVersions::getInstallPath('drupal/core'), which - // THROWS (not returns null) when the package is not installed, so this must - // be guarded before the lookup. - if (! \Composer\InstalledVersions::isInstalled('drupal/core')) { - return; - } - - $drupalFinder = new \DrupalFinder\DrupalFinderComposerRuntime(); - - $drupalRoot = $drupalFinder->getDrupalRoot(); - if (is_string($drupalRoot) && $drupalRoot !== '') { - $rectorConfig->autoloadPaths([ - $drupalRoot.'/core', - $drupalRoot.'/modules', - $drupalRoot.'/profiles', - $drupalRoot.'/themes', - ]); - } - - // phpstan-drupal lives in the analysed project's vendor dir, not ours. - $vendorDir = $drupalFinder->getVendorDir(); - if (is_string($vendorDir) && $vendorDir !== '') { - $phpstanDrupalExtension = $vendorDir.'/mglaman/phpstan-drupal/extension.neon'; - if (file_exists($phpstanDrupalExtension)) { - $rectorConfig->phpstanConfigs([$phpstanDrupalExtension]); - } - } -};