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

New sniff: add visibility to class constant declarations #15

Open
jrfnl opened this issue Jul 16, 2018 · 0 comments
Open

New sniff: add visibility to class constant declarations #15

jrfnl opened this issue Jul 16, 2018 · 0 comments

Comments

@jrfnl
Copy link
Member

jrfnl commented Jul 16, 2018

Sniff basics -
Fixable for PHP: 7.1+
Sniff type: Modernize
Fixer type: Safe (review recommended)

Short description of the sniff

Prior to PHP 7.1, class constants could not have visibility declared and would always be public. As of PHP 7.1, there is a choice between declaring class constants as public, protected or private.

Related PHPCompatibility sniff(s):

  • NewConstVisibility

PHP manual references:

Example code:

Detect the following code pattern(s):

class ClassConstants
{
    const MYCONST_A = 1;
}

And fix these to:

class ClassConstants
{
    public const MYCONST_A = 1;
}

Notes for implementation of the sniff:

  • This is only possible for class constants, so the scope of the const keyword will need to be carefully checked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant