PHP_CodeSniffer
PHP_CodeSniffer copied to clipboard
Squiz.ControlStructures.SwitchDeclaration: thorough review of the sniff code
While working on something else, I came across the Squiz.ControlStructures.SwitchDeclaration sniff, and saw the following issues:
- The sniff contains a number of whitespace/blank line related errors which are not currently auto-fixable, while I believe they could/should be auto-fixable.
- A number of the error messages do not use the
$dataparameter, but concatenate the error message together instead. This should be fixed. Also see: #1240 - Generally speaking, the sniff could do with a review with regards to the token walking being done.
- Fixer code should be reviewed to see if the fixer can handle all situations or could result in multiple loops. If the latter, the fixer code should be fixed.
Example - "'CASE keyword must be followed by a single space'",
SpacingAfterCaseerror code. The fixer doesn't appear to take into account that the whitespace after the "case" keyword could be multiple new lines. https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/2c13a9078eb3a680dfbda085eb90e6c6bb05a023/src/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L114-L122
There may be more issues, but this was just what I saw at first glance, so a thorough review would not go amiss.