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

Issue with PSR-12 behavior not according specification with spacing for anonymous classes #569

Closed
4 tasks done
rikvdh opened this issue Jul 21, 2024 · 5 comments
Closed
4 tasks done

Comments

@rikvdh
Copy link

rikvdh commented Jul 21, 2024

Describe the bug

Found while developing tests for PER2.0, I got the error: PSR12.Classes.AnonClassDeclaration.SpaceAfterKeyword, but when diving into specifications for PSR-12, I could not found anything related to spacing being required there.

Code sample

<?php

$foo = new class() {};
//             ^^

Here an error is raised about needing a space between the arguments for the class and the first opening-parenthesis. But nowhere in the specification, nor the errata, I can find on required spacing after class keywords.

What it should be is a bit ambiguous, but when it is not specified it should not be checked. It is 'class instantiation' and should require parentheses. But the space there should not be checked imo.

Custom ruleset

N/A

Expected behavior

I think we need to mute this error.

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • 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.
@jrfnl
Copy link
Member

jrfnl commented Jul 21, 2024

This was previously discussed in squizlabs/PHP_CodeSniffer#3200 and I don't think anything has changed in PSR12 since that discussion.

@rikvdh
Copy link
Author

rikvdh commented Jul 21, 2024

There is now in PER 2.0 a clear example which is then 'wrong'. I've submitted a proposal to fix this in the spec.

php-fig/per-coding-style#90

@jrfnl
Copy link
Member

jrfnl commented Jul 21, 2024

Also related: #47

@jrfnl
Copy link
Member

jrfnl commented Jul 27, 2024

@rikvdh As the PR to PER has been merged now, do you agree we can close this issue ?

@rikvdh
Copy link
Author

rikvdh commented Jul 27, 2024

Yes, could be closed now.

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