diff --git a/rules-tests/Transform/Rector/FileWithoutNamespace/RectorConfigBuilderRector/Fixture/sets_to_with_sets.php.inc b/rules-tests/Transform/Rector/FileWithoutNamespace/RectorConfigBuilderRector/Fixture/sets_to_with_sets.php.inc new file mode 100644 index 00000000000..e149a218b3d --- /dev/null +++ b/rules-tests/Transform/Rector/FileWithoutNamespace/RectorConfigBuilderRector/Fixture/sets_to_with_sets.php.inc @@ -0,0 +1,23 @@ +sets([SetList::DEAD_CODE]); +}; + +?> +----- +withSets([SetList::DEAD_CODE]); + +?> diff --git a/rules/Transform/Rector/FileWithoutNamespace/RectorConfigBuilderRector.php b/rules/Transform/Rector/FileWithoutNamespace/RectorConfigBuilderRector.php index fee4c2833a6..cf556b4cf3a 100644 --- a/rules/Transform/Rector/FileWithoutNamespace/RectorConfigBuilderRector.php +++ b/rules/Transform/Rector/FileWithoutNamespace/RectorConfigBuilderRector.php @@ -91,6 +91,7 @@ public function refactor(Node $node): ?Node $skips = new Array_(); $autoloadPaths = new Array_(); $bootstrapFiles = new Array_(); + $sets = new Array_(); foreach ($stmts as $rectorConfigStmt) { // complex stmts should be skipped, eg: with if else @@ -139,6 +140,9 @@ public function refactor(Node $node): ?Node } elseif ($name === 'ruleWithConfiguration') { $newExpr = $this->nodeFactory->createMethodCall($newExpr, 'withConfiguredRule', [$value, $args[1]->value]); $hasChanged = true; + } elseif ($name === 'sets') { + Assert::isAOf($value, Array_::class); + $sets->items = array_merge($sets->items, $value->items); } else { // implementing method by method return null; @@ -170,6 +174,11 @@ public function refactor(Node $node): ?Node $hasChanged = true; } + if ($sets->items !== []) { + $newExpr = $this->nodeFactory->createMethodCall($newExpr, 'withSets', [$sets]); + $hasChanged = true; + } + if ($hasChanged) { $stmt->expr = $newExpr; }