PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

Review error message creation

Open jrfnl opened this issue 4 months ago • 0 comments

While working on something else, I noticed a number of error messages in various sniffs using concatenation instead of passing variable parts of the error message to the add[Fixable]Error/Warning() methods via a $data array.

These are likely left-overs from long ago.

I believe it would be prudent to fix these up to follow the best practice of using %s placeholders and a $data array.

I seem to remember that even messages with placeholders can be changed from within a phpcs.xml[.dist] ruleset. Before executing this action, it should be investigated whether updating the error messages would constitute a breaking change. And if so, it will need to be evaluated if this action needs to wait until the next major release of PHPCS or can be included in an earlier minor/patch version.

Action list

Action list based on what I came across (likely to be reasonably complete, though a critical look at all error messages in the sniffs involved is warranted):

  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/fcfefc635209c324eb6ed47280d4cc5d245c7cd6/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php#L419
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/fcfefc635209c324eb6ed47280d4cc5d245c7cd6/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php#L476
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/fcfefc635209c324eb6ed47280d4cc5d245c7cd6/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php#L492
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/fcfefc635209c324eb6ed47280d4cc5d245c7cd6/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php#L213
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/fcfefc635209c324eb6ed47280d4cc5d245c7cd6/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php#L250
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/fcfefc635209c324eb6ed47280d4cc5d245c7cd6/src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L72
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/fcfefc635209c324eb6ed47280d4cc5d245c7cd6/src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L103
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/fcfefc635209c324eb6ed47280d4cc5d245c7cd6/src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L120
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/fcfefc635209c324eb6ed47280d4cc5d245c7cd6/src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L174
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/c5e7f483bcbdcf504c2547ad677755bf347bf407/src/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L82
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/c5e7f483bcbdcf504c2547ad677755bf347bf407/src/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L95
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/c5e7f483bcbdcf504c2547ad677755bf347bf407/src/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L132
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/c5e7f483bcbdcf504c2547ad677755bf347bf407/src/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L152
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/c5e7f483bcbdcf504c2547ad677755bf347bf407/src/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L224
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/c5e7f483bcbdcf504c2547ad677755bf347bf407/src/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php#L206
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/c5e7f483bcbdcf504c2547ad677755bf347bf407/src/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php#L240
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/c5e7f483bcbdcf504c2547ad677755bf347bf407/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php#L191
  • [ ] https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/c5e7f483bcbdcf504c2547ad677755bf347bf407/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php#L238

jrfnl avatar Sep 12 '25 01:09 jrfnl