Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassDeclarationSniff bug with readonly classes #3842

Closed
2 of 3 tasks
enumag opened this issue Jun 19, 2023 · 4 comments
Closed
2 of 3 tasks

ClassDeclarationSniff bug with readonly classes #3842

enumag opened this issue Jun 19, 2023 · 4 comments

Comments

@enumag
Copy link

enumag commented Jun 19, 2023

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:

  • I have searched the issue list and am not opening a duplicate issue.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the master branch of PHP_CodeSniffer.
@fredden
Copy link
Contributor

fredden commented Jun 19, 2023

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

  • PEAR.Classes.ClassDeclaration
  • PSR1.Classes.ClassDeclaration
  • PSR2.Classes.ClassDeclaration
  • Squiz.Classes.ClassDeclaration

@enumag
Copy link
Author

enumag commented Jun 19, 2023

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

PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\ClassDeclarationSniff

@fredden
Copy link
Contributor

fredden commented Jun 19, 2023

@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 3f7b9ba / #3826.

@enumag
Copy link
Author

enumag commented Jun 19, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants