Skip to content

Commit

Permalink
[EarlyReturn] Returns array of If_ on ChangeOrIfContinueToMultiContin…
Browse files Browse the repository at this point in the history
…ueRector (#854)
  • Loading branch information
samsonasik committed Sep 9, 2021
1 parent 70e4b3c commit c9f333d
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ public function getNodeTypes(): array

/**
* @param If_ $node
* @return null|If_[]
*/
public function refactor(Node $node): ?Node
public function refactor(Node $node): ?array
{
if (! $this->ifManipulator->isIfWithOnly($node, Continue_::class)) {
return null;
Expand All @@ -93,22 +94,23 @@ public function refactor(Node $node): ?Node
return $this->processMultiIfContinue($node);
}

private function processMultiIfContinue(If_ $if): If_
/**
* @return null|If_[]
*/
private function processMultiIfContinue(If_ $if): ?array
{
$node = clone $if;
/** @var Continue_ $continue */
$continue = $if->stmts[0];
$ifs = $this->createMultipleIfs($if->cond, $continue, []);
foreach ($ifs as $key => $if) {
if ($key === 0) {
$this->mirrorComments($if, $node);
}

$this->nodesToAddCollector->addNodeBeforeNode($if, $node);
// ensure ifs not removed by other rules
if ($ifs === []) {
return null;
}

$this->removeNode($node);
return $node;
$this->mirrorComments($ifs[0], $node);
return $ifs;
}

/**
Expand Down

0 comments on commit c9f333d

Please sign in to comment.