Skip to content

Commit

Permalink
[Php52] Ensure return $node only when node changed on ContinueToBreak…
Browse files Browse the repository at this point in the history
…InSwitchRector (#2283)

* [Php52] Ensure return $node only when node changed on ContinueToBreakInSwitchRector

* [Php52] Ensure return $node only when node changed on ContinueToBreakInSwitchRector

* [Php52] Ensure return $node only when node changed on ContinueToBreakInSwitchRector

* [Php52] Ensure return $node only when node changed on ContinueToBreakInSwitchRector

* [Php52] Ensure return $node only when node changed on ContinueToBreakInSwitchRector
  • Loading branch information
samsonasik committed May 11, 2022
1 parent 12fa940 commit 3216544
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3216544

Please sign in to comment.