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

feature request: make sure an exception is used #3844

Closed
enumag opened this issue Sep 8, 2020 · 5 comments
Closed

feature request: make sure an exception is used #3844

enumag opened this issue Sep 8, 2020 · 5 comments

Comments

@enumag
Copy link
Contributor

enumag commented Sep 8, 2020

Feature request

In my code I'm using some static exception factory methods similar to Doctrine's ORMException. For instance:

Today I found out that in some cases my code only called the method but did nothing with the returned exception - the throw statement was missing.

I'd like PHPStan to tell me about these "unused exception" cases.

@ondrejmirtes
Copy link
Member

I'm not sure what you exactly mean without a code sample but I'd guess this package does what you want: https://github.com/pepakriz/phpstan-exception-rules/

@ondrejmirtes
Copy link
Member

I'd guess it can be generalized into "Calling a method that doesn't have a side effect - report when the returned value isn't used".

@enumag
Copy link
Contributor Author

enumag commented Sep 8, 2020

I'm not sure what you exactly mean without a code sample but I'd guess this package does what you want: pepakriz/phpstan-exception-rules

No, I don't think so.

I'd guess it can be generalized into "Calling a method that doesn't have a side effect - report when the returned value isn't used".

Yup, agreed. 👍

@ondrejmirtes
Copy link
Member

This now works, but the method returning the exception must be tagged with @phpstan-pure: https://phpstan.org/r/feaca926-456c-40b8-96d5-a9c37eac6c99

Implemented in: phpstan/phpstan-src#412

@github-actions
Copy link

github-actions bot commented May 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 May 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants