Documenting return types #9221
Unanswered
ajaxStardust
asked this question in
Support
Replies: 1 comment 2 replies
-
Please reproduce your issues on phpstan.org/try. also make sure to check the docs:
and also PHP docs because for what you want you might not need PHPDocs at all, just native return types. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Salutations!
Since discovering PHPStan, I've been going through my code and adding PHPDoc comments as needed, as reported by PHPStan.
What is the correct way to document a return type, when That report is based on \Class::method() being commented as:
/** * method * * @param mixed $user_id * @return null */
PHPStan reports errors like the following:
Method Namespace\Class::method() should return null but returns false.
...then:
/** * method * * @param mixed $user_id * @return */
Method Namespace\Class::method() should return null but empty return statement found.
Changing the PHPDoc comment to the following results in PHPStan reporting a different error:
/** * method * * @param mixed $user_id * @return void */
Method with return type void returns false but should not return anything.
So what is the correct way to document the return to satisfy PHPStan?
Edit: Note, i'm using the Visual Studio Code extension, https://github.com/shishirui/phpdoc-comment-vscode-plugin
to assist in adding the PHPDoc comments. It is suggesting the comment be placed as "@return void", as in the 3rd example above.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions