Skip to content

Commit

Permalink
Add support for module_load_include into existing module_load_install…
Browse files Browse the repository at this point in the history
… rector.
  • Loading branch information
bbrala committed Dec 18, 2023
1 parent eab4674 commit ff33b93
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 32 deletions.
2 changes: 1 addition & 1 deletion config/drupal-9/drupal-9.4-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Replaces deprecated module_load_install call with ModuleHandler call.
*/
class ModuleLoadInstallRector extends AbstractRector
class ModuleLoadRector extends AbstractRector
{
/**
* {@inheritdoc}
Expand All @@ -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;
Expand All @@ -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
),
]);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* A simple example using the minimum number of arguments.
*/
function simple_example() {
module_load_install('example');

$module = 'simple';
module_load_install($module);

$type = 'install';
$module = 'example';
$name = 'name';
module_load_include($type, $module, $name);
module_load_include($type, $module);

module_load_include('install', 'example', 'name');
module_load_include('install', 'example');
}
?>
-----
<?php

/**
* A simple example using the minimum number of arguments.
*/
function simple_example() {
\Drupal::moduleHandler()->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');
}
?>

0 comments on commit ff33b93

Please sign in to comment.