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.3 | Generic/UpperCaseConstantName: add support for typed constants #332

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Feb 8, 2024

Description

This sniff is specifically targeted at constant names.

PHP 8.3 introduces typed constants. This means that the sniff now needs to jump over a potentially declared constant type to get at the constant name.

Fixed now.

Includes tests.

Suggested changelog entry

  • Generic.NamingConventions.UpperCaseConstantName : support for typed class constants

Related issues/external references

Related to #106
Fixes squizlabs/PHP_CodeSniffer#3927
Closes squizlabs/PHP_CodeSniffer#3936

Types of changes

  • New feature (non-breaking change which adds functionality)

@martinjoiner
Copy link

martinjoiner commented Feb 12, 2024

Have just manually tested this branch with the following code

class CompanyRegionsCommand extends Command
{
    private const int PAGE_SIZE = 40;
}

And I can confirm that the UpperCaseConstantNameSniff sniff no longer reports a false positive. Whereas before it wrongly thought the "int" part is the constant name it now understands this is a typehint.

👍 Good work Juliette @jrfnl

@jrfnl
Copy link
Member Author

jrfnl commented Feb 14, 2024

Unless there are objections/someone leaves a comments on this PR, I will merge this tomorrow.

This sniff is specifically targeted at constant names.

PHP 8.3 introduces typed constants. This means that the sniff now needs to jump over a potentially declared constant type to get at the constant name.

Fixed now.

Includes tests.

Fixes squizlabs/PHP_CodeSniffer 3927
Closes squizlabs/PHP_CodeSniffer 3936
@jrfnl jrfnl force-pushed the php-8.3/generic-uppercaseconstantname-support-typed-constants branch from 094ab91 to 45bf3ad Compare February 15, 2024 13:22
@jrfnl
Copy link
Member Author

jrfnl commented Feb 15, 2024

Rebased without changes. Merging once the build passes.

@jrfnl jrfnl merged commit 5529b4c into master Feb 15, 2024
44 checks passed
@jrfnl jrfnl deleted the php-8.3/generic-uppercaseconstantname-support-typed-constants branch February 15, 2024 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants