Skip to content
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

Merged
merged 1 commit into from Feb 1, 2022
Merged

Support narrowing down array_filter return type via string callable #938

merged 1 commit into from Feb 1, 2022

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Jan 22, 2022

@@ -0,0 +1,51 @@
<?php

namespace ArrayFilter;
Copy link
Contributor

@staabm staabm Jan 22, 2022

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

Copy link
Contributor Author

@herndlm herndlm Jan 30, 2022

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.

@ondrejmirtes
Copy link
Member

I think this is fine, feel free to mark it as ready :)

@herndlm herndlm marked this pull request as ready for review February 1, 2022 03:15
@herndlm
Copy link
Contributor Author

herndlm commented Feb 1, 2022

Guess you also don't have a simple solution for the following?

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.

@ondrejmirtes
Copy link
Member

The logic in some type-specifying extensions can be really complex making it impossible to rewrite it in AST.

@ondrejmirtes ondrejmirtes merged commit 1789915 into phpstan:master Feb 1, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@herndlm herndlm deleted the support-narrowing-down-array-filter-return-type-via-string-callable branch February 1, 2022 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants