e.g.
switch (...) {
case self::STRATEGY_EXACT:
// ...
}
leads to:
CASE statements must be defined using a colon
What standard are you using? Can you please specify actual code fragment being checked and error message code?
Actually, I don't have access to that, since this error message is from Scrutinizer CI.
But I suppose it is from PHP_CodeSniffer because the error message is an exact match.
PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase
(best guess based on #579)
I can't replicate this issue on version 2.6, 2.5 or 2.4 (or even as far back as 2.3, where the message was changed) so I'm not sure how it is being generated.
If you can, please post some code that replicates the problem.
The test code I am using, which passes under PSR2, is:
switch ($foo) {
case self::STRATEGY_EXACT:
echo 'foo';
break;
}
I've also alerted Scrutinizer CI on Twitter: https://twitter.com/teohhanhui/status/724833533592801280
Thanks a lot for providing that.
Turns out it has nothing to do with the SWITCH itself. It's the PHP7 T_COALESCE operator that comes before it that is the problem. It was being tokenized as two tokens as PHP wasn't providing a token in all versions. I committed a fix a few hours ago for this issue and it fixes the problem you are having.
The bug report (with fix commit attached) is here: https://github.com/squizlabs/PHP_CodeSniffer/issues/962
No expected release date yet though. If Scrutinizer CI is using PHP7, it _should_ already have the token. but if it is using an older PHP version, it's going to be generating errors.
Closing now as there isn't more I can do here now that the fix is committed for older PHP versions. I just need to make a release when I've cleared the current bug list.
Thanks again for getting back to me so quickly.
Most helpful comment
Thanks a lot for providing that.
Turns out it has nothing to do with the SWITCH itself. It's the PHP7 T_COALESCE operator that comes before it that is the problem. It was being tokenized as two tokens as PHP wasn't providing a token in all versions. I committed a fix a few hours ago for this issue and it fixes the problem you are having.
The bug report (with fix commit attached) is here: https://github.com/squizlabs/PHP_CodeSniffer/issues/962
No expected release date yet though. If Scrutinizer CI is using PHP7, it _should_ already have the token. but if it is using an older PHP version, it's going to be generating errors.
Closing now as there isn't more I can do here now that the fix is committed for older PHP versions. I just need to make a release when I've cleared the current bug list.
Thanks again for getting back to me so quickly.