-
-
Notifications
You must be signed in to change notification settings - Fork 89
Closed
Labels
Description
Describe the bug
I'm not certain if this is in scope, but I'm curious if phpcs could treat never
functions as comparable to exit;
Code sample
<?php
declare(strict_types=1);
function error(): never
{
// Do logging
exit;
}
switch ($Var) {
case 'one':
// Do stuff
break;
case 'two':
error();
case 'three':
// Do stuff
break;
}
Custom ruleset
<?xml version="1.0"?>
<ruleset name="PSR12">
<config name="testVersion" value="8.3-"/>
<arg name="extensions" value="php"/>
<arg name="ignore" value="vendor/"/>
<arg name="colors" />
<arg value="sp"/>
<rule ref="PSR12">
<exclude name="Generic.Files.LineLength.TooLong" />
</rule>
<rule ref="Generic.PHP.RequireStrictTypes" />
<rule ref="Generic.PHP.DisallowShortOpenTag" />
</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
---------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
---------------------------------------------------------------------------------------------------------------
1 | WARNING | A file should declare new symbols (classes, functions, constants, etc.) and cause no other
| | side effects, or it should execute logic with side effects, but should not do both. The first
| | symbol is defined on line 5 and the first side effect is on line 12.
| | (PSR1.Files.SideEffects.FoundWithSymbols)
16 | ERROR | There must be a comment when fall-through is intentional in a non-empty case body
| | (PSR2.ControlStructures.SwitchDeclaration.TerminatingComment)
---------------------------------------------------------------------------------------------------------------
Expected behavior
There should be no error on line 16, because it's unreachable.
The obvious workarounds of doing:
error();
break;
regrettably causes the 3rd party project phpstan to rightly throw an error than the break statement is unreachable. So it fixes the phpcs error, and creates a phpstan one. Making it a bit inconvenient.
Versions (please complete the following information)
Operating System | Gentoo Linux |
PHP version | 8.3.13 |
PHP_CodeSniffer version | 3.10.3 |
Standard | PSR12 |
Install type | composer |
Additional context
Add any other context about the problem here.
Please confirm:
- I have searched the issue list and am not opening a duplicate issue.
- I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- I have verified the issue still exists in the
master
branch of PHP_CodeSniffer.