[Php84] Fix ForeachToArrayAnyRector dropping elseif/else branches - #8480
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 oneifwithelseif/elsebranches, the rule kept only the firstifcondition and silently discarded the rest.The reported Guzzle
is_host_in_noproxy()collapsed to:dropping the exact-match, empty-value, and domain-suffix logic - broken output.
Fix
Bail out in both structure validators when the
ifcarrieselseifsor anelse, since those branches cannot be represented in a singlearray_anypredicate.Fixtures added for the early-return elseif/else case and the boolean-assignment else case.
https://claude.ai/code/session_01APZKnKT7DBy7AWZ7z3MGDa