InArrayFunctionTypeSpecifyingExtension
suggestions for improvements
#7275
Labels
InArrayFunctionTypeSpecifyingExtension
suggestions for improvements
#7275
Feature request
Hello there. While adding some types and types' tests for a wrapper function around
in_array()
in our codebase, I noticed some behavior could be improved.The most useful improvement I see is for an array
array<T|null>
, we could infer that after calling!in_array(null, $array)
,$array
isarray<T>
. So that this code would not trigger an inspection (currently does) : https://phpstan.org/r/a8dc5151-6acb-4a9f-b569-c6e658273608. Could be applied tobool
/false
too I guess, maybe others (I haven't thought a lot about other cases).Another one would be for an
array<T>
, we could infer that after callingin_array($anyValue, $array)
,$array
isnon-empty-array<T>
(I guess this one is self-explanatory 😄 ).What do you think ? :) Here's the recap' demo with
assertType
calls : https://phpstan.org/r/1981fe30-11e7-4b73-97a5-254cfc5dd9fa(I don't currently have the time to work on an implementation, but maybe someone will.)
Did PHPStan help you today? Did it make you happy in any way?
(I have a bunch of small issues to create, sorry if I don't come up with something new for each of them 🙏 )
The text was updated successfully, but these errors were encountered: