mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit 716ee0baa0e116478ba30e06ce68c7431b5d8504
716ee0baa0
[Naming] Handle used in arrow function param, then used again outer ArrowFunction on RenameParamToMatchTypeRector (#6046)
This commit is contained in:
parent
fbeb28108e
commit
6be87806c2
@ -5,16 +5,17 @@ namespace Rector\Naming;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Analyser\MutatingScope;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\Naming\PhpDoc\VarTagValueNodeRenamer;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
final class VariableRenamer
|
||||
{
|
||||
@ -53,8 +54,8 @@ final class VariableRenamer
|
||||
}
|
||||
$hasRenamed = \false;
|
||||
$currentStmt = null;
|
||||
$currentClosure = null;
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $functionLike->getStmts(), function (Node $node) use($oldName, $expectedName, $assign, &$isRenamingActive, &$hasRenamed, &$currentStmt, &$currentClosure) {
|
||||
$currentFunctionLike = null;
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $functionLike->getStmts(), function (Node $node) use($oldName, $expectedName, $assign, &$isRenamingActive, &$hasRenamed, &$currentStmt, &$currentFunctionLike) {
|
||||
// skip param names
|
||||
if ($node instanceof Param) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
@ -66,14 +67,14 @@ final class VariableRenamer
|
||||
if ($node instanceof Stmt) {
|
||||
$currentStmt = $node;
|
||||
}
|
||||
if ($node instanceof Closure) {
|
||||
$currentClosure = $node;
|
||||
if ($node instanceof FunctionLike) {
|
||||
$currentFunctionLike = $node;
|
||||
}
|
||||
if (!$node instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
// TODO: Should be implemented in BreakingVariableRenameGuard::shouldSkipParam()
|
||||
if ($this->isParamInParentFunction($node, $currentClosure)) {
|
||||
if ($this->isParamInParentFunction($node, $currentFunctionLike)) {
|
||||
return null;
|
||||
}
|
||||
if (!$isRenamingActive) {
|
||||
@ -87,16 +88,21 @@ final class VariableRenamer
|
||||
});
|
||||
return $hasRenamed;
|
||||
}
|
||||
private function isParamInParentFunction(Variable $variable, ?Closure $closure) : bool
|
||||
private function isParamInParentFunction(Variable $variable, ?FunctionLike $functionLike) : bool
|
||||
{
|
||||
if (!$closure instanceof Closure) {
|
||||
if (!$functionLike instanceof FunctionLike) {
|
||||
return \false;
|
||||
}
|
||||
$variableName = $this->nodeNameResolver->getName($variable);
|
||||
if ($variableName === null) {
|
||||
return \false;
|
||||
}
|
||||
foreach ($closure->params as $param) {
|
||||
$scope = $variable->getAttribute(AttributeKey::SCOPE);
|
||||
$functionLikeScope = $functionLike->getAttribute(AttributeKey::SCOPE);
|
||||
if ($scope instanceof MutatingScope && $functionLikeScope instanceof MutatingScope && $scope->equals($functionLikeScope)) {
|
||||
return \false;
|
||||
}
|
||||
foreach ($functionLike->getParams() as $param) {
|
||||
if ($this->nodeNameResolver->isName($param, $variableName)) {
|
||||
return \true;
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '6be29cb334c36a803a5a82a420f4b21e11b4389a';
|
||||
public const PACKAGE_VERSION = '716ee0baa0e116478ba30e06ce68c7431b5d8504';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-06-26 16:46:20';
|
||||
public const RELEASE_DATE = '2024-06-26 17:26:10';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user