Skip to content

Support parsing of PhpStan's conditional return types #1963

@crozet-magenta

Description

@crozet-magenta

Since phpstan 1.6 it is possible to use conditional return statements, phpstorm supports parsing this type of phpdoc since 2022.3.1 but it seems that the inspection provided by this plugin does not and returns some false positives in the inspection results.

As seen in the screenshots, if the parameter $required is set to true the function will return a non nullable value so the null pointer exception will not happen later:
Screenshot 2024-11-14 at 11 49 49
Screenshot 2024-11-14 at 11 50 08

Not sure that this change is possible/easy to do but it would be great if someone can have a look at it and see if it is possible to handle this case. (Currently I add a phpdoc comment to silence this inspection but it does not seem to be ideal)
Screenshot 2024-11-14 at 11 51 29

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions