-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add dynamic return type extension for get_post_types
#177
Add dynamic return type extension for get_post_types
#177
Conversation
The `get_post_types` function return either and array of `string` or an array of `WP_Post_Type` depending on the passed arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a new file with assertion tests, please? an example would be e.g. #144
Account for different results from `get_post_types` based on the arguments passed. Also submitted a pull request upstream and simply keeping this here in case that does not get merged. @todo Remove this extension if the pull request gets merged and released upstream szepeviktor/phpstan-wordpress#177
Could it be done with the new conditional type in WP stubs? |
good point, looks like this would work: https://phpstan.org/r/6e188841-6faf-4de8-9c0f-57ebabc3e626 |
Tests are now included should you decide to use this code. :) |
Thank you for your work. |
The conditional thing then must work for |
@lipemat Conditional return types arrived in php-stubs/wordpress-stubs#73 Thank you for your PR!! |
I will use your tests. |
Introduce GetPostTypesDynamicFunctionReturnTypeExtension service
The
get_post_types
function return either and array ofstring
or an array ofWP_Post_Type
depending on the passed arguments.https://developer.wordpress.org/reference/functions/get_post_types/#return