Description
if we know native haystack and needle types for a in_array, array_keys or array_search call, it would be great we could fix add a true as 3rd parameter in case its missing or can always be true. we should only fix when haystacks' iterable type is a super type of needle (strict comparison). the fixer must not change calls where equivalence cannot be proven.
Example: in_array($needle, X::VALS) into its strict counterpart in_array($needle, X::VALS, true).
https://phpstan.org/r/e288cf2a-08e5-4c06-9255-1a98eefc99fe
named arguments should be supported and calls using the splat operator should be skipped.
we should not fix calls which get their iterable-value type from a phpdoc, e.g.:
/** @return int[] */
function getArray(): array {}
function doFoo(int $i):bool {
return in_array($i, getArray());
}For array_keys(), only consider calls with at least two arguments, since the strictness flag matters only when a search value is supplied. Calls without a search value should remain unchanged.
The rule also reports calls to other functions, such as base64_decode(). Those calls should not be made fixable by this change.
Activity
[-]auto-fix "Call to function in_array() requires parameter #3 to be set."[/-][+]auto-fix "Call to function in_array() requires parameter #3 to be true."[/+][-]auto-fix "Call to function in_array() requires parameter #3 to be true."[/-][+]auto-fix "Call to function in_array() requires parameter #3 to be set/true."[/+]