From ec648dcab18931d98251280880dee81d72ff6fba Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 2 Sep 2026 10:55:45 +0200 Subject: [PATCH] [Naming] Fix partial rename in RenameVariableToMatchMethodCallReturnTypeRector when a nested arrow function has a param of the same name The tracked $currentFunctionLike is only updated on enter, so it lingers past its own body. A variable located after a nested arrow function was matched against that stale function-like params and skipped, renaming the assignment but not its later usage. Closes rectorphp/rector#9872 --- ..._usage_with_same_named_arrow_param.php.inc | 39 +++++++++++++++++++ .../Source/SortableBuilder.php | 28 +++++++++++++ rules/Naming/VariableRenamer.php | 6 +++ 3 files changed, 73 insertions(+) create mode 100644 rules-tests/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector/Fixture/rename_usage_with_same_named_arrow_param.php.inc create mode 100644 rules-tests/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector/Source/SortableBuilder.php diff --git a/rules-tests/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector/Fixture/rename_usage_with_same_named_arrow_param.php.inc b/rules-tests/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector/Fixture/rename_usage_with_same_named_arrow_param.php.inc new file mode 100644 index 00000000000..e7b45ecad43 --- /dev/null +++ b/rules-tests/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector/Fixture/rename_usage_with_same_named_arrow_param.php.inc @@ -0,0 +1,39 @@ +allowedSorts(fn (SortableBuilder $query): SortableBuilder => $query->defaultSort('x')) + ->defaultSort('part_type'); + + return $query->jsonPaginate(); + } +} + +?> +----- +allowedSorts(fn (SortableBuilder $query): SortableBuilder => $query->defaultSort('x')) + ->defaultSort('part_type'); + + return $sortableBuilder->jsonPaginate(); + } +} + +?> diff --git a/rules-tests/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector/Source/SortableBuilder.php b/rules-tests/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector/Source/SortableBuilder.php new file mode 100644 index 00000000000..9d995def6e9 --- /dev/null +++ b/rules-tests/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector/Source/SortableBuilder.php @@ -0,0 +1,28 @@ +getStartTokenPos() > $functionLike->getEndTokenPos()) { + return false; + } + $scope = $variable->getAttribute(AttributeKey::SCOPE); $functionLikeScope = $functionLike->getAttribute(AttributeKey::SCOPE);