-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Describe the bug
Using the sniff PSR2.ControlStructures.SwitchDeclaration
brings in an edge case for the error code TerminatingComment
when having try/finally in the switch case body
Code sample
<?php
$statusValue = mt_rand();
$resource = SomeClass::getWorker();
switch ( $statusValue ) {
case 0:
// fall-through
case 2:
try {
return $resource->doWork();
} finally {
$resource->release();
}
case 3:
$other = $code;
break;
}
Custom ruleset
<?xml version="1.0"?>
<ruleset name="My Custom Standard">
<rule ref="PSR2.ControlStructures.SwitchDeclaration" />
</ruleset>
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above... - Run
phpcs test.php ...
- See error message displayed
9 | ERROR | There must be a comment when fall-through is intentional
| | in a non-empty case body
| | (PSR2.ControlStructures.SwitchDeclaration.TerminatingComment)
Expected behavior
The try/finally always returns, that means there is no fall-through which does not need a comment.
That also the same when using finally + catch or catch alone
Versions (please complete the following information):
- OS: Windows 10
- PHP: 8.0
- PHPCS: 3.6.0
- Standard: -