-
Notifications
You must be signed in to change notification settings - Fork 509
Support narrowing down array_filter return type via string callable #938
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
Support narrowing down array_filter return type via string callable #938
Conversation
@@ -0,0 +1,51 @@ | |||
<?php | |||
|
|||
namespace ArrayFilter; |
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.
Separate test-cases for
- a string which is not callable
- A string to a class-method reference
- With a 3rd
mode
arg
would be useful
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.
adapted. what do you think? unfortunately narrowing-down the return type is currently only working for built-in functions. not entirely sure if this is a normal phpstan limitation or not. and/or if I could add support for it 🤔 you'll understand what I mean if you take a look at the last block of tests.
Basically I need to get the return statement and its expression of a function/method and use that instead. Did not find a way to achieve that yet.
src/Type/Php/ArrayFilterFunctionReturnTypeReturnTypeExtension.php
Outdated
Show resolved
Hide resolved
I think this is fine, feel free to mark it as ready :) |
Guess you also don't have a simple solution for the following?
|
The logic in some type-specifying extensions can be really complex making it impossible to rewrite it in AST. |
Thank you! |
Closes phpstan/phpstan#6417