-
-
Notifications
You must be signed in to change notification settings - Fork 20
Generate array shapes for PHPStan #21
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
Generate array shapes for PHPStan #21
Conversation
Thank you for your work, John! |
I've done that locally as part of my testing but there are several errors that need ignoring. I'll carry on with this later this week. |
That was a misunderstanding. Check only working PHP source code :) |
Ah sorry what I meant was I was using PHPStan to validate the generated array shapes (to check to syntax errors etc) and as part of that testing I had to ignore other unrelated errors. |
That is a valid point but there is no way in PHPStan to pick-and-choose source code parts. |
This PR is about us going to WordPress but WordPress should come to its senses! |
Yeah I would prefer it if WordPress used a more widely used syntax but its array hash notation does have one advantage over the syntax used by PHPStan in that each array element supports a description which is very useful when reading the code. |
I knew you support noobs!! |
Green to go 🟢 now that we have php-stubs/generator#5 |
# Conflicts: # composer.json
Co-authored-by: Viktor Szépe <viktor@szepe.net>
Co-authored-by: Viktor Szépe <viktor@szepe.net>
Thank you John for your work. I think it is ready to merge. Have you tested some of your projects with these array shapes? |
Yeah I've been testing this, mostly the functions with new I should do some more testing of the functions that now include |
I checked all the |
Work in progress. Fixes #15.
This converts the array hash notation that WordPress uses into an array shape that PHPStan understands, and appends a
@phpstan-param
tag for it to the docblock of the generated stub. It's fault tolerant so any incorrectly formatted array hashes should simply be ignored.Todo:
@param
@return
@phpstan-return
tags should be optional@param
marked as "Required"I tried to add handling for "Required" and "Optional" elements but core isn't consistent enough with its documentation and there aren't many anyway. Not worth worrying about in my opinion.
When the stubs are generated this adds:
@phpstan-param
tags@phpstan-return
tagsExample: