mirror of https://github.com/rectorphp/rector.git
[Php52] Ensure return $node only when node changed on ContinueToBreakInSwitchRector (#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
This commit is contained in:
parent
12fa9407f7
commit
32165444b1
|
@ -75,18 +75,29 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue