I do get a warning whenever I throw an exception in my code without explicitly stating it in the docblocs:
I know this can be fixed by adding @throw
tags, but the warning is actually not 100% true, as I do handle the exception in /app/Exceptions/Handler.php
. I would like to disable the warning for this single exception. Is this possible in PHPStan? I have not found anything in the docs, but in this blog post
How can I suppress the warning for my exception?
CodePudding user response:
As to why Symfony\Component\HttpKernel\Exception\NotFoundHttpException
is not reported -- they have different parents:
NotFoundHttpException
extendsHttpException
extends\RuntimeException
(which is in unchecked list)AuthenticationException
extends\Exception
CodePudding user response:
First of all, this is a PhpStorm hint, not a PHPStan.
The point of @throw
in docblock is to show you what exceptions your method can throw. If another developer or yourself reuses that method elsewhere, PhpStorm will immediately remind you of that exception and suggest you either wrap it in try-catch or move it to docblock for higher-level processing.
So I see no problem pointing this exception at @throw
.