squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

ClassDeclarationSniff bug with readonly classes #3842

Closed enumag closed 1 year ago

enumag commented 1 year ago

Describe the bug

The sniff removes a space and makes the code invalid

Code sample

final readonly class X implements Y {}

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. The sniff changes the code to
    final readonlyclass X implements Y {}

Expected behavior

The code should be unchanged.

Versions (please complete the following information)

Operating System debian
PHP version 8.2
PHP_CodeSniffer version 3.7.2
Standard custom
Install type composer

Please confirm:

fredden commented 1 year ago

@enumag please can you confirm what sniff you think is causing issues? You have mentioned ClassDeclarationSniff, but there are four sniffs named that:

enumag commented 1 year ago

Oh I'm sorry, didn't realize there was more than one of them.

PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\ClassDeclarationSniff
fredden commented 1 year ago

@enumag thanks for confirming. When I run bin/phpcbf -sp --standard=Squiz --sniffs=Squiz.Classes.ClassDeclaration issue-3842.php with the suggested input, I get expected output. I suspect this may have already been fixed in 3f7b9ba8544073fb2ff7c879c70d036090ebd95a / https://github.com/squizlabs/PHP_CodeSniffer/pull/3826.

enumag commented 1 year ago

Ah okay. It should work fine when 3.8.0 is released then. Thank you!