Skip to content

Commit

Permalink
[Transform] Allow transform bootstrapFiles() to withBootstrapFiles() …
Browse files Browse the repository at this point in the history
…on RectorConfigBuilderRector (#5633)
  • Loading branch information
samsonasik committed Feb 18, 2024
1 parent 85aba8e commit a4f2852
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->bootstrapFiles([
__DIR__ . '/constants.php',
]);
};

?>
-----
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return \Rector\Config\RectorConfig::configure()->withBootstrapFiles([
__DIR__ . '/constants.php',
]);

?>
Expand Up @@ -90,6 +90,7 @@ public function refactor(Node $node): ?Node
$paths = new Array_();
$skips = new Array_();
$autoloadPaths = new Array_();
$bootstrapFiles = new Array_();

foreach ($stmts as $rectorConfigStmt) {
// complex stmts should be skipped, eg: with if else
Expand Down Expand Up @@ -132,6 +133,9 @@ public function refactor(Node $node): ?Node
} elseif ($name === 'autoloadPaths') {
Assert::isAOf($value, Array_::class);
$autoloadPaths = $value;
} elseif ($name === 'bootstrapFiles') {
Assert::isAOf($value, Array_::class);
$bootstrapFiles = $value;
} else {
// implementing method by method
return null;
Expand All @@ -158,6 +162,11 @@ public function refactor(Node $node): ?Node
$hasChanged = true;
}

if ($bootstrapFiles->items !== []) {
$newExpr = $this->nodeFactory->createMethodCall($newExpr, 'withBootstrapFiles', [$bootstrapFiles]);
$hasChanged = true;
}

if ($hasChanged) {
$stmt->expr = $newExpr;
}
Expand Down

0 comments on commit a4f2852

Please sign in to comment.