diff --git a/rules-tests/Php84/Rector/Foreach_/ForeachToArrayAnyRector/Fixture/early_return_skip_if_with_elseif_else.php.inc b/rules-tests/Php84/Rector/Foreach_/ForeachToArrayAnyRector/Fixture/early_return_skip_if_with_elseif_else.php.inc new file mode 100644 index 00000000000..93836864346 --- /dev/null +++ b/rules-tests/Php84/Rector/Foreach_/ForeachToArrayAnyRector/Fixture/early_return_skip_if_with_elseif_else.php.inc @@ -0,0 +1,26 @@ +elseifs !== [] || $firstStmt->else instanceof Else_) { + return false; + } + $assignmentStmt = $firstStmt->stmts[0]; $breakStmt = $firstStmt->stmts[1]; @@ -315,6 +320,10 @@ private function isValidEarlyReturnForeachStructure(Foreach_ $foreach): bool $ifStmt = $foreach->stmts[0]; + if ($ifStmt->elseifs !== [] || $ifStmt->else instanceof Else_) { + return false; + } + if (count($ifStmt->stmts) !== 1) { return false; }