szepeviktor/phpstan-wordpress

False positives in `add_filter()` type checking

swissspidy opened this issue · 5 comments

Re-sharing from #107 (comment)

The new rules check that callbacks added for add_filter actually return a value.

In my initial testing it doesn't always work, the rule only seems to check the return type declaration, but is ignoring any @return docblocks.

Example:

https://github.com/GoogleForCreators/web-stories-wp/blob/c3b5eec59b0bb79dc096260f5c9614cffc3b3778/includes/Admin/Admin.php#L75-L78

The top three lines are getting flagged because those methods don't have a return type (just in PHPDoc).
The last one has a PHP return type and is not flagged.

@swissspidy Does the analysis pass if you add declare(strict_types=1); to the top of the file?

If so, I'll need to look into how PHPStan varies its type checking based on that strict flag because I haven't figured it out yet.

declare(strict_types=1); doesn't appear to make a difference.

I found another false-positive with a mixed return type (which currently cannot be distinguished from a no return which is also mixed I think). I'll also try to check if I can improve it. actually this might be the same problem.

I started adding some failing tests to #130