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

Unclear error message for missed constant enum #4967

Closed
fogush opened this issue May 6, 2021 · 4 comments
Closed

Unclear error message for missed constant enum #4967

fogush opened this issue May 6, 2021 · 4 comments
Labels
Milestone

Comments

@fogush
Copy link

fogush commented May 6, 2021

Bug report

An asterisk * for constant enumerations means all constants. When a function doesn't return all constants matched by the asterisk, PHPStan shows Method ... never returns string so it can be removed from the return typehint.. This looks really unclear. If the string word could be replaced with a specific list of constants that are not returned, it would be much better.

Code snippet that reproduces the problem

https://phpstan.org/r/31821eb7-2751-4a04-909f-dd8262fbfe0f

Expected output

Method Test::throwsPhpStanError() never returns StatusEnum::STATUS_OPEN so it can be removed from the return typehint.

@ondrejmirtes
Copy link
Member

Yeah, this is just a question of using VerbosityLevel::getRecommendedLevelByType() here: https://github.com/phpstan/phpstan-src/blob/b11218bcf1a281fd6a1bbac69c0700a0d50f1564/src/Rules/TooWideTypehints/TooWideMethodReturnTypehintRule.php#L99

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone May 6, 2021
@phpstan-bot
Copy link
Contributor

@fogush After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-22: Method Test::throwsPhpStanError() never returns string so it can be removed from the return typehint.
+22: Method Test::throwsPhpStanError() never returns 'open' so it can be removed from the return typehint.
Full report
Line Error
22 Method Test::throwsPhpStanError() never returns 'open' so it can be removed from the return typehint.

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src@838d1e4

@github-actions
Copy link

github-actions bot commented Jul 2, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants