False positive: Function apply_filters invoked with 3 parameters, 2 required.
andreasciamanna opened this issue · 4 comments
apply_filters
requires at least two arguments, but it can accept more as well.
The problem is that this information is only in the PHPDoc, while the function signature is just function apply_filters($tag, $value)
.
For instance, do_action
requires at least one argument (the hook tag), but, like apply_filters
, it can accept more arguments and this is specified in both the PHPDoc and the function signature: function do_action($tag, ...$arg)
.
This causes problems when the WP stubs are used in projects where apply_filters
is called with more than two arguments.
A quick tweak to the stub file solved the issue: function apply_filters( $tag, $value, ...$args ) {
.
However, I don't know if it's the right thing to do and since the stub file is generated, I suppose it might not be that easy to modify the output with that fix.
Thank you for your report!
Yes, it is known https://github.com/szepeviktor/phpstan-wordpress/blob/a5addc6470a5bff72716576329c2bbf90548feb1/example/phpstan.neon.dist#L10-L12
WP 5.x brought tremendous improvements.
We are waiting for WordPress core to fix PHPDoc blocks.
I am not able to fix them (regex) one by one.
BTW This is the last PHPDoc problem :) I meet every day.
There is a trick though: if you put (sed
command) a dummy $dummy = func_get_args();
call in those functions PHPStan will not raise that error.
If you need me use Slack/Making WordPress!
If you need me use Slack/Making WordPress!
Thanks!
I'll do it if I get stuck :)