Skip to content

Commit

Permalink
[Transform] Transform rules() to withRules() on RectorConfigBuilderRe…
Browse files Browse the repository at this point in the history
…ctor (#5566)
  • Loading branch information
samsonasik committed Feb 6, 2024
1 parent 09398c3 commit 9a44c19
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Transform\Rector\FileWithoutNamespace\RectorConfigBuilderRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(ReturnUnionTypeRector::class);
$rectorConfig->rules([
RectorConfigBuilderRector::class,
TypedPropertyFromAssignsRector::class
]);
};

?>
-----
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Transform\Rector\FileWithoutNamespace\RectorConfigBuilderRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;

return \Rector\Config\RectorConfig::configure()->withRules([ReturnUnionTypeRector::class, RectorConfigBuilderRector::class, TypedPropertyFromAssignsRector::class]);

?>
Expand Up @@ -19,6 +19,7 @@
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;

/**
* @see \Rector\Tests\Transform\Rector\FileWithoutNamespace\RectorConfigBuilderRector\RectorConfigBuilderRectorTest
Expand Down Expand Up @@ -108,6 +109,9 @@ public function refactor(Node $node): ?Node

if ($this->isName($rectorConfigStmt->expr->name, 'rule')) {
$rules->items[] = new ArrayItem($rectorConfigStmt->expr->getArgs()[0]->value);
} elseif ($this->isName($rectorConfigStmt->expr->name, 'rules')) {
Assert::isAOf($rectorConfigStmt->expr->getArgs()[0]->value, Array_::class);
$rules->items = array_merge($rules->items, $rectorConfigStmt->expr->getArgs()[0]->value->items);
} else {
// implementing method by method
return null;
Expand Down

0 comments on commit 9a44c19

Please sign in to comment.