[Naming] Fixes #5587 Skip RenameParamToMatchTypeRector when used in ClassMethod stmts (#5588)

This commit is contained in:
Abdul Malik Ikhsan 2021-02-17 14:09:31 +07:00 committed by GitHub
parent 8e915ebe9b
commit 9e731713b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -6,6 +6,7 @@ namespace Rector\Naming\Guard;
use DateTimeInterface;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
@ -155,7 +156,17 @@ final class BreakingVariableRenameGuard
return true;
}
return $this->isDateTimeAtNamingConvention($param);
if ($this->isDateTimeAtNamingConvention($param)) {
return true;
}
return (bool) $this->betterNodeFinder->find((array) $classMethod->stmts, function (Node $node) use ($expectedName): bool {
if (! $node instanceof Variable) {
return false;
}
return $this->nodeNameResolver->isName($node, $expectedName);
});
}
private function isVariableAlreadyDefined(Variable $variable, string $currentVariableName): bool

View File

@ -0,0 +1,13 @@
<?php
namespace Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector\Fixture;
final class SkipUsed
{
public function run(Node $nd)
{
$this->betterNodeFinder->find($nd->stmts, function (Node $node) use ($nd) {
return $nd !== $node;
});
}
}