PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 22, 2022

[FIXED] How to disable warning for specific exceptions?

 November 22, 2022     exception, laravel, phpstan, phpstorm     No comments   

Issue

I do get a warning whenever I throw an exception in my code without explicitly stating it in the docblocs: enter image description here

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 https://phpstan.org/blog/bring-your-exceptions-under-control it seems that one can have unchecked & checked exceptions, and I believe unchecked exceptions do not need to be declared. However, marking my exception unchecked in phpstan.neon does not get rid of the error:

 exceptions:
        uncheckedExceptionClasses:
            - 'app\Exceptions\AuthenticationException'

I also noticed that the Symfony\Component\HttpKernel\Exception\NotFoundHttpException exception does not trigger the warning. I am not sure why, but it seems there is already a set of exceptions where no @throw is needed.

enter image description here

How can I suppress the warning for my exception?


Solution

As Bob has correctly stated this comes from PhpStorm itself and not PHPStan.

You can add any exception to the Unchecked Exception list so it will be ignored by PhpStorm at Settings/Preferences | PHP | Analysis

https://www.jetbrains.com/help/phpstorm/php-missing-throws-tag-s.html

enter image description here


As to why Symfony\Component\HttpKernel\Exception\NotFoundHttpException is not reported -- they have different parents:

  • NotFoundHttpException extends HttpException extends \RuntimeException (which is in unchecked list)
  • AuthenticationException extends \Exception


Answered By - LazyOne
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing