-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Prevent Squiz.Commenting.FunctionCommentThrowTag.Missing failing for exceptions caught in method #3685
Comments
We are facing the same behaviour in PhpStorm 2022.2.3 on macOS Monterey 12.6 and also in the automated phpcs test pipelines on azure cloud. |
Any updates on this? |
See squizlabs/PHP_CodeSniffer#3685 PHP Code Sniffer mistakes the following code, thinking that it throws an exception even though the exception is caught in place. ```php try { throw new WP_HTML_Unsupported_Exception( 'The outside never sees me.' ); } catch ( WP_HTML_Unsupported_Excepted $e ) { return false; } ``` This patch adds an exclude for the HTML Processor where PHPCS is confused. Until that bug is fixed this is a pragmatic solution to avoiding the need to change actual code around a bug in a linting tool. When that bug is fixed and it no longer gets confused this exclusion should be removed.
See squizlabs/PHP_CodeSniffer#3685 PHP Code Sniffer mistakes the following code, thinking that it throws an exception even though the exception is caught in place. ```php try { throw new WP_HTML_Unsupported_Exception( 'The outside never sees me.' ); } catch ( WP_HTML_Unsupported_Excepted $e ) { return false; } ``` This patch adds an exclude for the HTML Processor where PHPCS is confused. Until that bug is fixed this is a pragmatic solution to avoiding the need to change actual code around a bug in a linting tool. When that bug is fixed and it no longer gets confused this exclusion should be removed.
See squizlabs/PHP_CodeSniffer#3685 PHP Code Sniffer mistakes the following code, thinking that it throws an exception even though the exception is caught in place. ```php try { throw new WP_HTML_Unsupported_Exception( 'The outside never sees me.' ); } catch ( WP_HTML_Unsupported_Excepted $e ) { return false; } ``` This patch adds an exclude for the HTML Processor where PHPCS is confused. Until that bug is fixed this is a pragmatic solution to avoiding the need to change actual code around a bug in a linting tool. When that bug is fixed and it no longer gets confused this exclusion should be removed.
Any updates on this issue? |
@celorodovalho As far as I can see, nobody has submitted a PR to fix this, so no. |
@jrfnl I could submit it by myself if I have time to learn how it works. |
@celorodovalho If you do, please make sure you submit the PR to the new repo. This repo is abandoned and https://github.com/PHPCSStandards/PHP_CodeSniffer is its successor. See: #3932 |
Describe the bug
Using the
Squiz.Commenting.FunctionCommentThrowTag.Missing
to warn when a method is throwing an exception not mentioned in the PHPdoc is requiring users to add the @throw tag even when the exception is caught in the same scope of the method.Code sample
Custom ruleset
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above.phpcs test.php
Expected behavior
The rule shouldn't trigger for users to set the @throws tag on the method PHPdoc since in the end the method won't be throwing this exception outside of its scope.
Versions (please complete the following information):
Additional context
This is conflicting with other inspections applied by some IDEs (like PHPStorm) which indicates the @throws tag is not necessary.
The text was updated successfully, but these errors were encountered: