[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:
Abdul Malik Ikhsan 2022-05-11 14:07:42 +07:00 committed by GitHub
parent 12fa9407f7
commit 32165444b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -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;
}