From eb83bb1c0bc77d4a20cbd2531cbe3ed40deb177a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 21 Oct 2026 00:29:58 +0700 Subject: [PATCH 1/2] [perf] Use of existing IS_INSIDE_BYREF_FUNCTION_LIKE attribute over IS_BYREF_RETURN --- .../SimplifyUselessVariableRector.php | 2 +- src/NodeTypeResolver/Node/AttributeKey.php | 2 -- .../NodeVisitor/ByRefNodeVisitor.php | 19 +------------------ 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php b/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php index 62cf7e577e1..663ae07978d 100644 --- a/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php +++ b/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php @@ -123,7 +123,7 @@ private function shouldSkipStmt(Return_ $return, Stmt $previousStmt): bool return true; } - if ($return->getAttribute(AttributeKey::IS_BYREF_RETURN) === true) { + if ($return->getAttribute(AttributeKey::IS_INSIDE_BYREF_FUNCTION_LIKE) === true) { return true; } diff --git a/src/NodeTypeResolver/Node/AttributeKey.php b/src/NodeTypeResolver/Node/AttributeKey.php index a8d933970b0..c65de9ebb2b 100644 --- a/src/NodeTypeResolver/Node/AttributeKey.php +++ b/src/NodeTypeResolver/Node/AttributeKey.php @@ -93,8 +93,6 @@ final class AttributeKey public const string IS_BYREF_VAR = 'is_byref_var'; - public const string IS_BYREF_RETURN = 'is_byref_return'; - public const string IS_BEING_ASSIGNED = 'is_being_assigned'; public const string IS_ASSIGN_OP_VAR = 'is_assign_op_var'; diff --git a/src/PhpParser/NodeVisitor/ByRefNodeVisitor.php b/src/PhpParser/NodeVisitor/ByRefNodeVisitor.php index dcec8419060..81dea5e1377 100644 --- a/src/PhpParser/NodeVisitor/ByRefNodeVisitor.php +++ b/src/PhpParser/NodeVisitor/ByRefNodeVisitor.php @@ -20,7 +20,7 @@ use Rector\PhpParser\NodeTraverser\SimpleNodeTraverser; /** - * Marks by-ref returns (IS_BYREF_RETURN / IS_INSIDE_BYREF_FUNCTION_LIKE) and by-ref variables + * Marks by-ref returns IS_INSIDE_BYREF_FUNCTION_LIKE and by-ref variables * (IS_BYREF_VAR) from a single FunctionLike entry, sharing the one node subscription. */ final class ByRefNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface @@ -62,23 +62,6 @@ private function decorateByRefReturn(FunctionLike $functionLike, array $stmts): } SimpleNodeTraverser::decorateWithAttributeValue($stmts, AttributeKey::IS_INSIDE_BYREF_FUNCTION_LIKE, true); - - $this->simpleCallableNodeTraverser->traverseNodesWithCallable( - $stmts, - static function (Node $node): int|null|Node { - // avoid nested functions or classes - if ($node instanceof Class_ || $node instanceof FunctionLike) { - return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; - } - - if (! $node instanceof Return_) { - return null; - } - - $node->setAttribute(AttributeKey::IS_BYREF_RETURN, true); - return $node; - } - ); } /** From 16b4fd90673b27735feca16c5123607240fa14b8 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 20 Oct 2026 17:32:00 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- src/PhpParser/NodeVisitor/ByRefNodeVisitor.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/PhpParser/NodeVisitor/ByRefNodeVisitor.php b/src/PhpParser/NodeVisitor/ByRefNodeVisitor.php index 81dea5e1377..4074a1b7dca 100644 --- a/src/PhpParser/NodeVisitor/ByRefNodeVisitor.php +++ b/src/PhpParser/NodeVisitor/ByRefNodeVisitor.php @@ -10,9 +10,6 @@ use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; use PhpParser\Node\FunctionLike; -use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\Return_; -use PhpParser\NodeVisitor; use PhpParser\NodeVisitorAbstract; use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface; use Rector\NodeTypeResolver\Node\AttributeKey;