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
Create a file called test.php with the code sample above...
Run phpcs test.php ...
See error message displayed
FILE: /Users/earthiverse/Code/Test.php
-------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------------------
8 | ERROR | [x] The readonly declaration must come after the visibility declaration (PSR2.Classes.PropertyDeclaration.ReadonlyBeforeVisibility)
-------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------------
Time: 37ms; Memory: 8MB
Expected behavior
The line with readonly private int $two should also have an error.
Versions
Operating System
MacOS 14.4.1
PHP version
8.3.4
PHP_CodeSniffer version
3.9.1
Standard
PSR2, PSR12
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.
The text was updated successfully, but these errors were encountered:
@earthiverse Thank you for reporting this. I've changed the type from "bug" to "feature request" (enhancement) as the PSR2.Classes.PropertyDeclaration sniff does not support constructor property promotion at all - and neither PSR2 nor PSR12 would expect it to, as both predate constructor property promotion, let alone readonly properties.
As things are, what with the sniff being based on the AbstractVariableSniff, adding support for examining properties declared via constructor property promotion to the sniff would likely warrant a complete rewrite of the sniff.
Describe the bug
PSR2.Classes.PropertyDeclaration.ReadonlyBeforeVisibility
doesn't apply when constructor property promotion is usedCode sample
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Expected behavior
The line with
readonly private int $two
should also have an error.Versions
Please confirm:
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: