Consider optional keys in ConstantArrayType removeFirst and removeLast #1352
+146
−21
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.
... and get rid of
getConstantArrays
in NodeScopeResolver forarray_pop
andarray_shift
.This seems to be also fixing problems with the optional keys. green test cases from this PR for comparison with the latest 1.7.x state which is broken IMO
array_pop: https://phpstan.org/r/99745329-2125-46a3-8fe6-ea4afdfc754e
array_shift: https://phpstan.org/r/751ff62d-d672-4ef8-9db1-5abbb6cf4a15
The added tests show that apparently
ArrayPopFunctionReturnTypeExtension
andArrayShiftFunctionReturnTypeExtension
are not working correctly either ("should be" comments), but I'd like to look at that in another PR if that's ok. Maybe a bug somewhere else in ConstantArrayType itself 🤔 But I also have an idea for replacing those getConstantArrays calls as well.My main motivation is to prepare stuff I can use in the
ConstantArrayType::slice
adaption. But now, since I learned that I can replace some of the potentially badly-scaling array gather & modify in a loop & unify code parts in general, I want to get rid of what I can :D