You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attributes are set on anonymous classes, phpcs inappropriately flag PSR12.Classes.ClassInstantiation.MissingParentheses violation
Code sample
<?php$class1 = newclass {
#[SomeAttribute('summary')]
publicconstSOME_STUFF = 'foo';
};
$class2 = new #[SomeAttribute('summary')] class {
publicconstSOME_STUFF = 'foo';
};
Custom ruleset
PSR12
To reproduce
Steps to reproduce the behavior:
Create a file called test.php with 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
phpcbf shouldn'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
----------------------------------------------------------------------
gsherwood
changed the title
Usage of attributes on anonymous class is not properly raise PSR12.Classes.ClassInstantiation.MissingParentheses
PSR12.Classes.ClassInstantiation.MissingParentheses false positive using attributes on anonymous class
Dec 12, 2021
Describe the bug
When attributes are set on anonymous classes, phpcs inappropriately flag
PSR12.Classes.ClassInstantiation.MissingParentheses
violationCode sample
Custom ruleset
PSR12
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above..../vendor/bin/phpcs --standard=PSR12 test.php ...
Expected behavior
phpcbf
shouldn't attempt to fix by producing invalid codeVersions (please complete the following information):
Additional context
phpcbf will produce invalid code:
and resulting file:
The text was updated successfully, but these errors were encountered: