PHPCompatibility / PHPModernizer

External PHPCS standard with auto-fixers to modernize legacy codebases
GNU Lesser General Public License v3.0
10 stars 0 forks source link

New sniff: add visibility to class constant declarations #15

Open jrfnl opened 6 years ago

jrfnl commented 6 years ago
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):

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: