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

False positive Squiz.PHP.NonExecutableCode.Unreachable when using goto statement #3796

Open
Chi-teck opened this issue Apr 11, 2023 · 1 comment

Comments

@Chi-teck
Copy link

Code sample

<?php

if (TRUE) {
  goto success;
}
throw new \Exception();
success:
echo 'It works!';

Output

--------------------------------------------------------------------------------------------------------------------------------------
 7 | WARNING | [ ] Code after the THROW statement on line 6 cannot be executed (Squiz.PHP.NonExecutableCode.Unreachable)
 8 | WARNING | [ ] Code after the THROW statement on line 6 cannot be executed (Squiz.PHP.NonExecutableCode.Unreachable)
--------------------------------------------------------------------------------------------------------------------------------------

Not the the violation reported twice by some reason.

@DannyvdSluijs
Copy link

I've tried to reproduce and I was able to reproduce, the required steps are:

  1. Take the above content and put it in a file (repro/3796.php)
  2. Run phpcs from the current master branch (commit b0ecdf1) using the Squiz standard./bin/phpcs --standard=Squiz -s repro/3796.php
  3. The output contains the above mentioned erroneous output.

Output:

FILE: /**/**/**/PHP_CodeSniffer/repro/3796.php
----------------------------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AND 2 WARNINGS AFFECTING 5 LINES
----------------------------------------------------------------------------------------------------------------------------------
 1 | ERROR   | [ ] Missing file doc comment (Squiz.Commenting.FileComment.Missing)
 3 | ERROR   | [x] TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
   |         |     (Generic.PHP.LowerCaseConstant.Found)
 5 | ERROR   | [x] No blank line found after control structure (Squiz.WhiteSpace.ControlStructureSpacing.NoLineAfterClose)
 7 | WARNING | [ ] Code after the THROW statement on line 6 cannot be executed (Squiz.PHP.NonExecutableCode.Unreachable)
 8 | WARNING | [ ] Code after the THROW statement on line 6 cannot be executed (Squiz.PHP.NonExecutableCode.Unreachable)
 8 | ERROR   | [x] Expected 1 newline at end of file; 0 found (PSR2.Files.EndFileNewline.NoneFound)
----------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------

Time: 137ms; Memory: 8MB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants