PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

Squiz.ControlStructures.SwitchDeclaration: thorough review of the sniff code

Open jrfnl opened this issue 2 months ago • 0 comments

While working on something else, I came across the Squiz.ControlStructures.SwitchDeclaration sniff, and saw the following issues:

  1. 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.
  2. A number of the error messages do not use the $data parameter, but concatenate the error message together instead. This should be fixed. Also see: #1240
  3. Generally speaking, the sniff could do with a review with regards to the token walking being done.
  4. 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'", SpacingAfterCase error 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.

jrfnl avatar Nov 09 '25 22:11 jrfnl