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;