diff --git a/config/drupal-9/drupal-9.4-deprecations.php b/config/drupal-9/drupal-9.4-deprecations.php index 16d66f83..8c5ab1c2 100644 --- a/config/drupal-9/drupal-9.4-deprecations.php +++ b/config/drupal-9/drupal-9.4-deprecations.php @@ -4,5 +4,5 @@ return static function (Rector\Config\RectorConfig $rectorConfig): void { // Change record https://www.drupal.org/node/3220952 - $rectorConfig->rule(\DrupalRector\Drupal9\Rector\Deprecation\ModuleLoadInstallRector::class); + $rectorConfig->rule(\DrupalRector\Drupal9\Rector\Deprecation\ModuleLoadRector::class); }; diff --git a/docs/rules_overview.md b/docs/rules_overview.md index 251bb3b1..f6580895 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -715,15 +715,22 @@ Fixes deprecated `AssertLegacyTrait::getRawContent()` calls
-### ModuleLoadInstallRector +### ModuleLoadRector Fixes deprecated `module_load_install()` calls -- class: [`DrupalRector\Drupal9\Rector\Deprecation\ModuleLoadInstallRector`](../src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector.php) +- class: [`DrupalRector\Drupal9\Rector\Deprecation\ModuleLoadRector`](../src/Drupal9/Rector/Deprecation/ModuleLoadRector.php) ```diff -module_load_install('example'); -+\Drupal\Core\Extension\ModuleHandler::loadInclude('example', 'install'); ++\Drupal::moduleHandler()->loadInclude('example', 'install'); + $type = 'install'; + $module = 'example'; + $name = 'name'; +-module_load_include($type, $module, $name); +-module_load_include($type, $module); ++\Drupal::moduleHandler()->loadInclude($module, $type, $name); ++\Drupal::moduleHandler()->loadInclude($module, $type); ```
diff --git a/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector.php b/src/Drupal9/Rector/Deprecation/ModuleLoadRector.php similarity index 64% rename from src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector.php rename to src/Drupal9/Rector/Deprecation/ModuleLoadRector.php index bffa01d9..866623ae 100644 --- a/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector.php +++ b/src/Drupal9/Rector/Deprecation/ModuleLoadRector.php @@ -12,7 +12,7 @@ /** * Replaces deprecated module_load_install call with ModuleHandler call. */ -class ModuleLoadInstallRector extends AbstractRector +class ModuleLoadRector extends AbstractRector { /** * {@inheritdoc} @@ -35,6 +35,12 @@ public function refactor(Node $node): ?Node\Expr\CallLike $args[] = new Node\Arg(new Node\Scalar\String_('install')); return $this->nodeFactory->createMethodCall($this->nodeFactory->createStaticCall('Drupal', 'moduleHandler'), 'loadInclude', $args); + } elseif ($this->getName($node->name) === 'module_load_include') { + $newArgs = $args = $node->getArgs(); + $newArgs[0] = $args[1]; + $newArgs[1] = $args[0]; + + return $this->nodeFactory->createMethodCall($this->nodeFactory->createStaticCall('Drupal', 'moduleHandler'), 'loadInclude', $newArgs); } return null; @@ -46,10 +52,20 @@ public function getRuleDefinition(): RuleDefinition new CodeSample( <<<'CODE_BEFORE' module_load_install('example'); +$type = 'install'; +$module = 'example'; +$name = 'name'; +module_load_include($type, $module, $name); +module_load_include($type, $module); CODE_BEFORE , <<<'CODE_AFTER' -\Drupal\Core\Extension\ModuleHandler::loadInclude('example', 'install'); +\Drupal::moduleHandler()->loadInclude('example', 'install'); +$type = 'install'; +$module = 'example'; +$name = 'name'; +\Drupal::moduleHandler()->loadInclude($module, $type, $name); +\Drupal::moduleHandler()->loadInclude($module, $type); CODE_AFTER ), ]); diff --git a/tests/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector/fixture/basic.php.inc b/tests/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector/fixture/basic.php.inc deleted file mode 100644 index 7857c2fc..00000000 --- a/tests/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector/fixture/basic.php.inc +++ /dev/null @@ -1,25 +0,0 @@ - ------ -loadInclude('example', 'install'); - - $module = 'simple'; - \Drupal::moduleHandler()->loadInclude($module, 'install'); -} -?> diff --git a/tests/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector/ModuleLoadInstallRectorTest.php b/tests/src/Drupal9/Rector/Deprecation/ModuleLoadRector/ModuleLoadRectorTest.php similarity index 82% rename from tests/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector/ModuleLoadInstallRectorTest.php rename to tests/src/Drupal9/Rector/Deprecation/ModuleLoadRector/ModuleLoadRectorTest.php index 37e36032..cebd2d9c 100644 --- a/tests/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector/ModuleLoadInstallRectorTest.php +++ b/tests/src/Drupal9/Rector/Deprecation/ModuleLoadRector/ModuleLoadRectorTest.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Drupal9\Rector\Deprecation\ModuleLoadInstallRector; +namespace Drupal9\Rector\Deprecation\ModuleLoadRector; use Iterator; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -class ModuleLoadInstallRectorTest extends AbstractRectorTestCase +class ModuleLoadRectorTest extends AbstractRectorTestCase { /** * @covers ::refactor diff --git a/tests/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector/config/configured_rule.php b/tests/src/Drupal9/Rector/Deprecation/ModuleLoadRector/config/configured_rule.php similarity index 54% rename from tests/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector/config/configured_rule.php rename to tests/src/Drupal9/Rector/Deprecation/ModuleLoadRector/config/configured_rule.php index eab586ad..f9b9c03a 100644 --- a/tests/src/Drupal9/Rector/Deprecation/ModuleLoadInstallRector/config/configured_rule.php +++ b/tests/src/Drupal9/Rector/Deprecation/ModuleLoadRector/config/configured_rule.php @@ -2,10 +2,10 @@ declare(strict_types=1); -use DrupalRector\Drupal9\Rector\Deprecation\ModuleLoadInstallRector; +use DrupalRector\Drupal9\Rector\Deprecation\ModuleLoadRector; use DrupalRector\Tests\Rector\Deprecation\DeprecationBase; use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { - DeprecationBase::addClass(ModuleLoadInstallRector::class, $rectorConfig, false); + DeprecationBase::addClass(ModuleLoadRector::class, $rectorConfig, false); }; diff --git a/tests/src/Drupal9/Rector/Deprecation/ModuleLoadRector/fixture/basic.php.inc b/tests/src/Drupal9/Rector/Deprecation/ModuleLoadRector/fixture/basic.php.inc new file mode 100644 index 00000000..11609627 --- /dev/null +++ b/tests/src/Drupal9/Rector/Deprecation/ModuleLoadRector/fixture/basic.php.inc @@ -0,0 +1,43 @@ + +----- +loadInclude('example', 'install'); + + $module = 'simple'; + \Drupal::moduleHandler()->loadInclude($module, 'install'); + + $type = 'install'; + $module = 'example'; + $name = 'name'; + \Drupal::moduleHandler()->loadInclude($module, $type, $name); + \Drupal::moduleHandler()->loadInclude($module, $type); + + \Drupal::moduleHandler()->loadInclude('example', 'install', 'name'); + \Drupal::moduleHandler()->loadInclude('example', 'install'); +} +?>