-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
PHP 8.4 | PSR2/PropertyDeclaration: add support for final properties #950
base: master
Are you sure you want to change the base?
PHP 8.4 | PSR2/PropertyDeclaration: add support for final properties #950
Conversation
Includes handling the modifier order when `final` is used. This introduces a new `FinalAfterVisibility` error code. Includes tests. Note: the modifier keyword order checks could probably do with some optimization, but that can be handled later.
@@ -56,6 +56,11 @@ public function getErrorList() | |||
82 => 1, | |||
84 => 1, | |||
86 => 1, | |||
90 => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So something I noticed generally with the tests in phpcs is that the actual error messages used aren't tested as much - you can see how I addressed tests for sniffs at https://github.com/DanielEScherzer/common-phpcs, I test against the output of the report instead of just the line numbers. Would you be interested in me porting that to phpcs so that we can test error messages too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I am definitely very aware of that problem and have some ideas about this too, but hadn't gotten round to actioning it yet (priorities, priorities).
If you'd be open to it, I'd be very happy to brainstorm the various options (and consequences of those!) in a call some time after next week. Feel free to ping me on Mastodon or X to set up a day/time.
$scopePtr = $phpcsFile->findPrevious(Tokens::$scopeModifiers, ($stackPtr - 1)); | ||
$finalPtr = $phpcsFile->findPrevious(T_FINAL, ($stackPtr - 1)); | ||
if ($finalPtr > $scopePtr) { | ||
$error = 'The final declaration must come before the visibility declaration'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PSR2 predates final properties, but technically https://www.php-fig.org/psr/psr-2/ just says that final needs to come before visibility and it doesn't limit that to methods, so looks great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly and yes, I did check PSR-PER before adding this new check 😉
Description
Includes handling the modifier order when
final
is used. This introduces a newFinalAfterVisibility
error code.Includes tests.
Note: the modifier keyword order checks could probably do with some optimization, but that can be handled later.
Suggested changelog entry
final
modifier keyword is placed before a visibility keyword. Errors will be reported via a newFinalAfterVisibility
error code.Related issues/external references
Related to #734, follow up to #834 and #907