-
Notifications
You must be signed in to change notification settings - Fork 140
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 PHPStan/Psalm templates #124
Comments
I don't think there is a way to automatically "generate" the @template annotations. I cannot analyze those files automatically. But the idea is very good, and I could make exceptions for those functions and have them written "by hand". Now, the question is: where can I find a complete list of such functions? Would you have an idea how I can find those? |
I think @ondrejmirtes may know that for phpstan, or @muglug for psalm |
Some situations can be described by generics, but a lot of them are more complex and require custom logic. PHPStan has "dynamic return type extensions" for this purpose and they're here in this directory (besides type-specifying extensions for functions like https://github.com/phpstan/phpstan/tree/master/src/Type/Php The problem is that they're not 1:1 reusable with |
@ondrejmirtes now that phpstan does implement templates, do you think we can generate them in safe? |
You might be able to describe some situations with generics, but not everything. |
I found eg. this https://github.com/vimeo/psalm/blob/master/src/Psalm/Internal/Provider/ReturnTypeProvider/StrReplaceReturnTypeProvider.php Perhaps we should be able to port this logic into something like |
Currently methods like
preg_replace
have a return type ofstring|array
specified.When in reality that return type is dependant on the input.
Static analysis tools, like PHPStan and Psalm can be made aware of this by using
@template
annotations, like so:https://phpstan.org/r/4f0fc5ec-ad1a-45e8-a592-a46106267d67
This means that the tools can understand what exactly the output is going to be, if they can infer the input types.
Would it be possible to add those annotations to the generated code?
The text was updated successfully, but these errors were encountered: