-
-
Notifications
You must be signed in to change notification settings - Fork 523
Description
Is your feature request related to a problem?
The issue is that type declaration in function/method when are used with filters can be a nightmare. Specifically because your code can get a fatal error if the other code from by plugins/themes doesn't pass as the documentation says.
So the culprit is you instead of the original author.
Describe the solution you'd like
After discussing on slack and PHPstan-wordpress the best solution is:
- Get the function/method on
add_filter - Check if has type declaration
- In that case add an alert to the developer to avoid for those reason
The only issue is that PHPCS doesn't check multiple files so the function is not in the same file cannot do this check. Anyway usually filters are together with the function or code in the same file as "standard" so I think that this case is very minimal to worry about. It is better to start with this detection and see if improve the code quality of plugins etc before thinking to add this support on other tool like phpstan.
Additional context (optional)
- https://core.trac.wordpress.org/ticket/51525 - Add new functions apply_filters_single_type() and apply_filters_ref_array_single_type()
- Alert when add_filter is used with a function with type hinting szepeviktor/phpstan-wordpress#64
- https://github.com/slevomat/coding-standard#slevomatcodingstandardtypehintsparametertypehint-