Skip to content
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.1 | PSR12/ConstantVisibility: allow for class constants to be final #3527

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jan 5, 2022

PHP 8.1 introduces the ability to declare class constants as final.

The tokenization of the final keyword in this context appears to be consistent PHPCS cross-version, so AFAICS no changes are needed to the PHP tokenizer.

However, the PSR12.Properties.ConstantVisibility sniff does need to allow for them.

Includes unit tests.

Ref: https://wiki.php.net/rfc/final_class_const

Fixes #3526

Related to #3479


Notes:

  • The test failures are unrelated to this PR and PR FileComment: update year in test file #3525 is already open to fix those.
  • I've done a cursory scan of all sniffs referring to the T_CONST token and could not find any other sniffs which would need adjusting for this PHP change.

…final`

PHP 8.1 introduces the ability to declare class constants as `final`.

The tokenization of the `final` keyword in this context appears to be consistent PHPCS cross-version, so AFAICS no changes are needed to the PHP tokenizer.

However, the `PSR12.Properties.ConstantVisibility` sniff does need to allow for them.

Includes unit tests.

Ref: https://wiki.php.net/rfc/final_class_const
@jrfnl jrfnl force-pushed the feature/3526-psr12-constantvisibility-bug-fix-final branch from 7c2d3b1 to 1b1fc31 Compare January 10, 2022 03:06
@jrfnl
Copy link
Contributor Author

jrfnl commented Jan 10, 2022

Rebased to get a passing build.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Jan 10, 2022
@gsherwood gsherwood added this to the 3.7.0 milestone Jan 10, 2022
gsherwood added a commit that referenced this pull request Jan 10, 2022
@gsherwood gsherwood merged commit 1b1fc31 into squizlabs:master Jan 10, 2022
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Jan 10, 2022
@gsherwood
Copy link
Member

Thanks for fixing this

@jrfnl jrfnl deleted the feature/3526-psr12-constantvisibility-bug-fix-final branch January 10, 2022 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

PSR12.Properties.ConstantVisibility false positive when using public final const syntax
2 participants