From f8bda529f2b7f68be54b2fbbc6763d83db2ffeb4 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 11 Oct 2026 00:26:51 +0200 Subject: [PATCH] [DeadCode] Skip deep body walk when no removable assign in RemoveUnusedVariableAssignRector --- .../Rector/Assign/RemoveUnusedVariableAssignRector.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php index 60487201d1a..1f33bff9129 100644 --- a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php +++ b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php @@ -94,12 +94,15 @@ public function refactor(Node $node): null|ClassMethod|Function_ return null; } - // we cannot be sure here - if ($this->shouldSkip($stmts)) { + $assignedVariableNamesByStmtPosition = $this->resolvedAssignedVariablesByStmtPosition($stmts); + if ($assignedVariableNamesByStmtPosition === []) { return null; } - $assignedVariableNamesByStmtPosition = $this->resolvedAssignedVariablesByStmtPosition($stmts); + // we cannot be sure here, deep walk only when there is a candidate to remove + if ($this->shouldSkip($stmts)) { + return null; + } $hasChanged = false;