-
-
Notifications
You must be signed in to change notification settings - Fork 87
Open
Description
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: Review error message creation #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.
PHP_CodeSniffer/src/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php
Lines 114 to 122 in 2c13a90
$error = 'CASE keyword must be followed by a single space'; $fix = $phpcsFile->addFixableError($error, $nextCase, 'SpacingAfterCase'); if ($fix === true) { if ($tokens[($nextCase + 1)]['type'] !== 'T_WHITESPACE') { $phpcsFile->fixer->addContent($nextCase, ' '); } else { $phpcsFile->fixer->replaceToken(($nextCase + 1), ' '); } }
There may be more issues, but this was just what I saw at first glance, so a thorough review would not go amiss.