Skip to content

Commit

Permalink
Defer type-resolving in ForeachToInArrayRector (#3756)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored May 7, 2023
1 parent 0f07aac commit ce46293
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ private function shouldSkipForeach(Foreach_ $foreach): bool
return true;
}

if (!$foreach->stmts[0] instanceof If_) {
return true;
}

$nextNode = $foreach->getAttribute(AttributeKey::NEXT_NODE);
if (! $nextNode instanceof Node) {
return true;
Expand All @@ -149,7 +153,6 @@ private function shouldSkipForeach(Foreach_ $foreach): bool
}

$returnExpression = $nextNode->expr;

if (! $returnExpression instanceof Expr) {
return true;
}
Expand All @@ -163,7 +166,7 @@ private function shouldSkipForeach(Foreach_ $foreach): bool
return true;
}

return ! $foreach->stmts[0] instanceof If_;
return false;
}

private function shouldSkipIf(If_ $if): bool
Expand Down

0 comments on commit ce46293

Please sign in to comment.