[DogFood] Skip call(configure) on UpgradeRectorConfigRector (#2119)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Abdul Malik Ikhsan 2022-04-22 05:43:09 +07:00 committed by GitHub
parent 0c649b2e38
commit 465b3f61d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 9 deletions

View File

@ -0,0 +1,20 @@
<?php
namespace Rector\Tests\DogFood\Rector\Closure\UpgradeRectorConfigRector\Fixture;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;
return static function (RectorConfig $rectorConfig): void {
$services = $rectorConfig->services();
$services->set(RenameClassRector::class)
->call('configure', [[
'old_2' => 'new_2',
]])
->call('configure', [[
'old_4' => 'new_4',
]]);
$rectorConfig->import(__DIR__ . '/first_config.php');
$rectorConfig->import(__DIR__ . '/second_config.php');
};

View File

@ -6,7 +6,6 @@ namespace Rector\DogFood\Rector\Closure;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
@ -143,16 +142,13 @@ CODE_SAMPLE
$nodeVarType = $this->nodeTypeResolver->getType($node->var);
if ($nodeVarType instanceof FullyQualifiedObjectType && $nodeVarType->getClassName() === self::SERVICE_CONFIGURATOR_CLASS) {
if ($this->isFoundFluentServiceCall($node)) {
return null;
}
$isPossiblyServiceDefinition = (bool) $this->betterNodeFinder->findFirstPreviousOfNode(
$node,
function (Node $node): bool {
if (! $node instanceof MethodCall) {
return false;
}
$methodCall = $this->fluentChainMethodCallNodeAnalyzer->resolveRootMethodCall($node);
return $methodCall instanceof Expr;
}
fn (Node $node): bool => $this->isFoundFluentServiceCall($node)
);
if ($isPossiblyServiceDefinition) {
@ -222,6 +218,16 @@ CODE_SAMPLE
return $this->isNames($paramType, [self::CONTAINER_CONFIGURATOR_CLASS, self::RECTOR_CONFIG_CLASS]);
}
private function isFoundFluentServiceCall(Node $node): bool
{
if (! $node instanceof MethodCall) {
return false;
}
$chains = $this->fluentChainMethodCallNodeAnalyzer->collectMethodCallNamesInChain($node);
return count($chains) > 1;
}
/**
* @param Arg[] $args
*/