Closed mundschenk-at closed 2 years ago
Guten Tag @mundschenk-at!! 👋🏻
We are doing that over at WordPress core stubs.
https://github.com/php-stubs/wordpress-stubs/blob/df4eef79b6a7f835e9c31a75e7ef1f513a0cb03d/visitor.php#L814-L821
But it works during parsing with nikic/php-parser
.
So
@phpstan-param array{ ... }
tagsThat's it!
💡 BTW "WordPress Documentation Standards" is not a standard. (no one else in the World follows it)
💡 BTW "WordPress Documentation Standards" is not a standard. (no one else in the World follows it)
Please don't preach. It is a standard within the WordPress ecosystem, which as far WordPress plugins are concerned, matters more than adoption in the wider PHP community.
Okay-okay. Sorry. I'm just very angry for me being part of this ecosystem.
So
- parse original WP-style code
- insert
@phpstan-param array{ ... }
tags- use it in static analysis
That's it!
How would I integrate this solution into a PHStan check? I really don't want to statically insert additional tags that simply mirror existing information in another format. I'm fine with an additional preprocessing step that can be automated from e.g. a composer script (or a GitHub action, though I'd prefer being able to continue to run all checks locally).
Okay-okay. Sorry. I'm just very angry for me being part of this ecosystem.
That I can understand very well. It's why I have been neglecting my plugins, because project leadership & lack of governance continues to disappoint.
Yes!
Develop a tiny tool that inserts @phpstan-param
tags based on the above linked file
then run it just before static analysis in your CI workflow.
OK, I see. So there is no existing tooling. I fear that creating that will be beyond the time I am currently willing to spare on WordPress stuff.
creating that
I would very much star ⭐ that project of yours!
Come to think about this, wouldn't this be a good addition for this extension? It already does something similar for hook @param
tags, no?
I think that phpstan-wordpress
in its current form is a space 👨🏻🚀 age tool for WordPress developers.
The php-stubs/wordpress-stubs
package converts WordPress syntax into PHPStan syntax here: https://github.com/php-stubs/wordpress-stubs/blob/df4eef79b6a7f835e9c31a75e7ef1f513a0cb03d/visitor.php#L641-L645 . Ideally that code should be moved from php-stubs/wordpress-stubs
to php-stubs/generator
so it can be used by packages other than WordPress core.
Is there currently any good solution (other than disabling the warning) for PHPStan not recognizing WordPress Documentation Standards array shape definitions?