diff --git a/rules-tests/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector/Fixture/mirror_comment_assign_method_call.php.inc b/rules-tests/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector/Fixture/mirror_comment_assign_method_call.php.inc new file mode 100644 index 00000000000..8b9290dc5a3 --- /dev/null +++ b/rules-tests/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector/Fixture/mirror_comment_assign_method_call.php.inc @@ -0,0 +1,29 @@ +query(); + } +} + +?> +----- +query(); + } +} + +?> diff --git a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php index 3b3f34bd857..b14f4283309 100644 --- a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php +++ b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php @@ -109,7 +109,9 @@ public function refactorWithScope(Node $node, Scope $scope): ?ClassMethod if ($this->hasCallLikeInAssignExpr($assign, $scope)) { // clean safely $cleanAssignedExpr = $this->cleanCastedExpr($assign->expr); - $node->stmts[$stmtPosition] = new Expression($cleanAssignedExpr); + $newExpression = new Expression($cleanAssignedExpr); + $this->mirrorComments($newExpression, $currentStmt); + $node->stmts[$stmtPosition] = $newExpression; } else { unset($node->stmts[$stmtPosition]); }