-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Describe the bug
When attributes are set on anonymous classes, phpcs inappropriately flag PSR12.Classes.ClassInstantiation.MissingParentheses violation
Code sample
<?php
$class1 = new class {
#[SomeAttribute('summary')]
public const SOME_STUFF = 'foo';
};
$class2 = new #[SomeAttribute('summary')] class {
public const SOME_STUFF = 'foo';
};Custom ruleset
PSR12
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.phpwith the code sample above... - Run
./vendor/bin/phpcs --standard=PSR12 test.php ... - See error message displayed
-------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------
8 | ERROR | [x] Parentheses must be used when instantiating a new class
-------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------
Expected behavior
- Should'nt report an error at Line 8
phpcbfshouldn't attempt to fix by producing invalid code
Versions (please complete the following information):
- OS: Linux Fedora 34
- PHP: 8.0
- PHPCS: 3.6.1
- Standard: PSR12
Additional context
phpcbf will produce invalid code:
./src/vendor/bin/phpcbf --standard=PSR12 test.php
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE FIXED REMAINING
----------------------------------------------------------------------
/home/mvacelet/workspace/tuleap/test.php 1 0
----------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
----------------------------------------------------------------------
and resulting file:
<?php
$class1 = new class {
#[SomeAttribute('summary')]
public const SOME_STUFF = 'foo';
};
$class2 = new() #[SomeAttribute('summary')] class {
public const SOME_STUFF = 'foo';
};Reactions are currently unavailable