mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-22 02:36:52 +01:00
ChangeAndIfToEarlyReturnRector: fix test expectation in if_in_foreach fixture (#4711)
* fix test expectation in if_in_foreach fixture * fixed method name which was misleading * fix variable name * adjust impl
This commit is contained in:
parent
f718d90cd2
commit
fe47bc2cc7
@ -122,9 +122,9 @@ CODE_SAMPLE
|
||||
$this->addNodesAfterNode($ifs, $node);
|
||||
$this->addNodeAfterNode($ifReturn, $node);
|
||||
|
||||
$ifParentReturn = $this->getIfParentReturn($node);
|
||||
if ($ifParentReturn !== null) {
|
||||
$this->removeNode($ifParentReturn);
|
||||
$ifNextReturn = $this->getIfNextReturn($node);
|
||||
if ($ifNextReturn !== null && !$this->isIfInLoop($node)) {
|
||||
$this->removeNode($ifNextReturn);
|
||||
}
|
||||
|
||||
$this->removeNode($node);
|
||||
@ -221,7 +221,7 @@ CODE_SAMPLE
|
||||
$ifs[0]->setAttribute(AttributeKey::COMMENTS, $nodeComments);
|
||||
}
|
||||
|
||||
private function getIfParentReturn(If_ $if): ?Return_
|
||||
private function getIfNextReturn(If_ $if): ?Return_
|
||||
{
|
||||
$nextNode = $if->getAttribute(AttributeKey::NEXT_NODE);
|
||||
if (! $nextNode instanceof Return_) {
|
||||
@ -279,4 +279,11 @@ CODE_SAMPLE
|
||||
}
|
||||
return $nextNode instanceof Return_;
|
||||
}
|
||||
|
||||
private function isIfInLoop(If_ $if): bool
|
||||
{
|
||||
$parentLoop = $this->betterNodeFinder->findFirstParentInstanceOf($if, [Stmt\Foreach_::class, Stmt\For_::class, Stmt\While_::class]);
|
||||
|
||||
return $parentLoop !== null;
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ class IfInForeachClass
|
||||
return;
|
||||
}
|
||||
$this->processNameOrIdentifier($node);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user