-
-
Notifications
You must be signed in to change notification settings - Fork 73
PHP 8.4 | Report final properties in File::getMemberProperties()
#834
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
Conversation
From #734
It turns out we don't actually need to update |
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.
@DanielEScherzer Thank you for working on this and for your willingness to contribute to PHP_CodeSniffer.
Code-wise this PR is looking good. ✅
If you don't mind, I'd like to see a few more tests added though.
While I'm pretty certain, based on the code, that things will work correctly, I'd still like to safeguard that for the future.
I'm thinking along the lines of:
final
property without other modifiers or typefinal
property without other modifiers, but with type declaration- property with multiple modifiers with some variations in the order of the keywords (
final
as first, middle, last keyword)
Other than that I've left two nitpick remarks inline and CI is pointing to a tiny CS fix which is needed.
getMethodParameters()
It turns out we don't actually need to update getMethodParameters(), because final properties don't seem to work for constructor promotion
Nice find. I'd be curious to see some more stress testing of constructor property promotion:
- Does it also not work when there is a hook attached ?
As for PHPCS, I'm in two minds about the consequences of this for the getMethodParameters()
method though.
- One the one hand: agreed - let's not support it in that method until PHP itself does. I.e. let's not handle it.
- On the other hand: PHPCS is generally speaking parse error/live coding tolerant, so things shouldn't break on coding mistakes, so even though
getMethodParameters()
may not need to support thefinal
keyword in method declarations (yet), we may still want to be tolerant tofinal
keywords being used in constructor property promotion, i.e. we may want to silently ignore it.
And if the method would already do so, maybe we should just add a test for the method to document that behaviour.
Having said that, let's move this discussion to #734/another PR, as it shouldn't block this PR and doesn't have to be solved at the same time.
Follow up actions
I've updated #734 to mention this PR and added your name to the second task for final
properties.
Please let me know if you would also like to take on the third task for adding support for final
properties (sniff updates), in which case, I'll add your name to it to "claim" the task (and prevent multiple people working on the same thing). I can already think of a number of sniffs which will need updates.
I'd also like to invite you to make the same changes as made in this PR for PHPCSUtils (BCFile::getMemberProperties()
and ObjectDeclarations::getMemberProperties()
Variables::getMemberProperties()
). Feel free to say no, but I just wanted to mention it in case you're interested.
For reference in case anyone is looking for it - these changes are based on the "Final Hooks" section in this PHP 8.4 RFC: https://wiki.php.net/rfc/property-hooks#interfaces |
Happy to help - I've been using codesniffer for years, and I figure instead of just asking when this would be done I could try and help out
done
Promoted hooks work fine from my testing
I figured I would start small, so I didn't do
If you can list the sniffs, I can take a look
I can take a look, I don't think I had ever seen those utilities before |
Thank you for that!
I meant the combination of constructor property promotion with a
Sounds like a plan and yes, I agree, a separate patch is best. I have a suspicion that #17860 may be rejected (or rather: was not implemented) for technical reasons. I also wouldn't surprised if changing it would need an RFC.
I haven't got a list, but the following sniffs come to mind, though I'd recommend doing a code base wide search on the use of These are some sniffs which come to mind straight away - they may need updates, and even if the code doesn't need to change, they are likely to need tests safeguarding that they handle the new syntax correctly anyway:
|
What technical reasons? It didn't take me too long to implement, and since PHP allows promoting hooks, why not final properties? But we can continue the discussion there (or on php/php-src#17861 with my patch)
I'll take a look, but not today - I was only planning to read through #734 and see if there was anything I might understand enough to contribute, but then I got an itch to code and sent this patch, and then I discovered the php-src bug and sent a patch for that, and I didn't really have the time today for any of that :) |
I honestly don't know, but quite often these type of things are left out for technical reasons, as in: there is something in the engine which make it complicated or a suspicion that it might block a future iteration. Glad to hear you got it working easily though. I'm following the ticket. |
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.
@DanielEScherzer Thank you for your work on this. I'll merge it once the build has passed.
Thanks - turns out the build didn't past, I think I fixed it now - I've been having trouble running the test suite on my computer, so that is why I didn't catch it. Do you want me to squash this, or can you do it when merging? |
@DanielEScherzer Thanks for fixing that up. Out of curiousity - what issue are you running into when running the tests locally ? It would help to understand this, to see if there are any potential improvements to be made to the contributing guide and/or Composer scripts.
Thanks for asking, I'll do a squash-merge, so all good. |
Errors about classes being redeclared, but in the same place - for both |
Hmm... curious.... I'll be happy to jump on a call with you to try and figure out what's going on there as this is a new one for me, but let's move that out of this ticket. Feel free to ping me on Mastodon or X (@jrf_nl on both) to get a call sorted. |
Update File::getMemberProperties() to report when a property is marked as final. Update existing tests (which are all for non-final properties) to expect that the property not be marked as final, and add a new test case for a final that should be, and is, marked as final. Part of #734
Update File::getMemberProperties() to report when a property is marked as final. Update existing tests (which are all for non-final properties) to expect that the property not be marked as final, and add a new test case for a final that should be, and is, marked as final. Part of #734
PHPCS 3.12.0 adds support for reporting if properties are final; polyfill the upstream method and copy over the tests. Ref: PHPCSStandards/PHP_CodeSniffer#834 Closes PHPCSStandards#645
* BCFile::getMemberProperties(): sync with upstream PHPCS 3.12.0 adds support for reporting if properties are final; polyfill the upstream method and copy over the tests. Ref: PHPCSStandards/PHP_CodeSniffer#834 Closes #645 * Update `Variables::getMemberProperties()` * Linting * BCFile::getMemberProperties(): make compatible with PHPCS 4.x ... and remove some redundant end comments.
Description
Update
File::getMemberProperties()
to report when a property is marked as final. Update existing tests (which are all for non-final properties) to expect that the property not be marked as final, and add a new test case for a final that should be, and is, marked as final.Suggested changelog entry
PHP 8.4 | Report final properties in
File::getMemberProperties()
Related issues/external references
Related to #734
Types of changes
PR checklist