diff --git a/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php b/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php index 86d3786cfa3..9668a8fb658 100644 --- a/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php +++ b/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php @@ -75,18 +75,29 @@ public function getNodeTypes(): array /** * @param Switch_ $node */ - public function refactor(Node $node): Switch_ + public function refactor(Node $node): ?Switch_ { + $hasChanged = false; foreach ($node->cases as $case) { foreach ($case->stmts as $key => $caseStmt) { if (! $caseStmt instanceof Continue_) { continue; } - $case->stmts[$key] = $this->processContinueStatement($caseStmt); + $newStmt = $this->processContinueStatement($caseStmt); + if ($newStmt === $caseStmt) { + continue; + } + + $case->stmts[$key] = $newStmt; + $hasChanged = true; } } + if (! $hasChanged) { + return null; + } + return $node; }