Skip to content

[Php84] Fix ForeachToArrayAnyRector dropping elseif/else branches - #8480

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-9900-foreach-array-any-elseif
Sep 11, 2026
Merged

[Php84] Fix ForeachToArrayAnyRector dropping elseif/else branches#8480
TomasVotruba merged 1 commit into
mainfrom
fix-9900-foreach-array-any-elseif

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Sep 11, 2026

Copy link
Copy Markdown
Member

Fixes #9900

Reported via demo: https://getrector.com/demo/47467d38-e31b-478a-ac1e-de0ee5bda472

Problem

array_any() takes a single predicate. When a foreach body is one if with elseif/else branches, the rule kept only the first if condition and silently discarded the rest.

The reported Guzzle is_host_in_noproxy() collapsed to:

return array_any($noProxyArray, fn($area) => $area === '*');

dropping the exact-match, empty-value, and domain-suffix logic - broken output.

Fix

Bail out in both structure validators when the if carries elseifs or an else, since those branches cannot be represented in a single array_any predicate.

Fixtures added for the early-return elseif/else case and the boolean-assignment else case.

https://claude.ai/code/session_01APZKnKT7DBy7AWZ7z3MGDa

array_any only takes a single condition, so a foreach whose if has
elseif/else branches cannot be represented without losing logic. Bail
out when the if carries elseifs or an else instead of keeping only the
first condition.

Fixes #9900

Claude-Session: https://claude.ai/code/session_01APZKnKT7DBy7AWZ7z3MGDa
@TomasVotruba
TomasVotruba merged commit 0f6aca4 into main Sep 11, 2026
44 checks passed
@TomasVotruba
TomasVotruba deleted the fix-9900-foreach-array-any-elseif branch September 11, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

ForeachToArrayAnyRector incorrect refactoring: array_any

1 participant