-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#6840 Report useless array filter #1077
#6840 Report useless array filter #1077
Conversation
8317d8e
to
91c6a48
Compare
I'm looking at this - it's really nice, Some observations that would make this even better:
|
That's what this PR checks for. Do you mean the opposite? Calling
|
Yes, that's what I meant, the rule should report both always-truthy and always-falsy arrays :) |
USE_BOTH without a callback only uses the first arg (= value) AFAIK, see also https://github.com/phpstan/phpstan-src/blob/1.4.10/tests/PHPStan/Analyser/data/array-filter.php#L36 But better double-check :) if the referenced test is wrong, I need to fix smth in the ArrayFilter extension |
I checked, passing
|
Ah maybe that explains why the key mode test above my rererence also looks weird 😅 would be interesting if and how it filters |
91c6a48
to
58fc6cf
Compare
It doesn't filter at all:
I've added support for reporting arrays with only falsey values. |
8d6237f
to
4ac9256
Compare
|
The failure is definitely related as the file contains this: Feel free to modify the file to contains something that's valid, like |
4ac9256
to
713dc09
Compare
Turns out |
bb60b4d
to
7f6853a
Compare
7f6853a
to
b29a267
Compare
I pushed some extra commits to adjust this to my taste. |
Thank you. |
Also to keep the BC promise (https://phpstan.org/user-guide/backward-compatibility-promise) I had to do this: 7627b52
|
@leongersen fyi I think null callables would work fine, they only work since PHP 8 and weirdly only ever filter by value (= ignore any given mode) |
New branch based on 1.5.x, I could not reopen #1076.
Implements phpstan/phpstan#6840.