Open franss22 opened 1 month ago
I was able to reproduce this error. Here is a simplified code snippet that causes the same problem:
switch ($value) {
case 'one':{
doSomething();
}
default:
return 'default';
}
I haven't investigated deeply, but on a quick look, it seems that the curly brackets and the lack of return
or break
in the case
statement are somehow tripping the tokenizer, and the T_RETURN
token is missing its scope information.
I believe this may be the same issue as previously reported in https://github.com/squizlabs/PHP_CodeSniffer/issues/3794, which is still open, but does contain an analysis of the underlying issues.
Describe the bug
SwitchDeclarationSniff throws a fatal error on some switch statements, stopping phpcbf execution.
Code sample
this is the switch statement that causes the error. Deleting this statement lets the formatter finish (but i obviously cant remove the switch as a fix to the formatter not working).
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above.phpcbf --standard=PSR12 test.php
Expected behavior
phpcbf should fix the switch statement sniff without crashing
Versions (please complete the following information)
Please confirm
master
branch of PHP_CodeSniffer.