-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Demo: Add conditional return type for $args array of get_posts - Can we? #134
Conversation
Why do people use Now I feel that I support/encourage people to use this |
@johnbillion Please comment on this PR. |
There's a dynamic return type extension. That's why used it as an example. I thought we can't do dynamic return types via the function map when it comes to array keys and their values. However, it appears I was wrong. |
I have to check again, but I think it does not work with this void unions in core. (szepeviktor/phpstan-wordpress#176) |
Ok, there's a failed test now. I don't know why this didn't happen on my first run of phpunit. However, the test expectation is wrong. // The assertion:
$union = $_GET['foo'] ? (string)$_GET['string'] : 'fields';
assertType('array<int, int|WP_Post>', get_posts([$union => ''])); This is a string-constantString union for the key. The value is an empty string and therefor the return type is |
'the_title_attribute' => ["(\$args is string ? 'array<int, int>', 'int')"],
PHPStan ignoring the conditional return type means that the crt is somehow incorrect. This works for 'the_title_attribute' => ["(\$args is empty|array{'echo': true} ? void : string|void)"], @johnbillion I'm curious to hear your thoughts on this. This would enable us to bring over several functions from szepeviktor/phpstan-wordpress and rely on PHPStan to check all the maybes and unions. Also @herndlm, what do you think? |
If this allows us to remove some dynamic return type extensions from phpstan-wordpress then I'm in favour. I'm taking a look now. |
Replaced by #195 |
(PR for demonstration)
https://phpstan.org/r/5f05dffa-73cd-4c46-95f5-7b65702264a0
The actual value always matches the expected value in all of the dumps. Also phpunit passes all tests that I copy pasted from szepeviktor/phpstan-wordpress