Modernize: use class constants for constant arrays (public API)
Description
:warning: This PR depends on PR #1039, which needs to be merged first. ⚠️
This PR modernizes various usages of constant arrays in the public API to use class constants instead of properties.
The properties still exist, but are now deprecated and will be removed in PHPCS 5.0.
In a separate PR, which will be pulled at a later point in time (but before the 4.0.0 release), the same will be done for additional usages of constant arrays, which are not in the public API.
Modernize: Util\Common: use class constant for constant array
As the property was in the public API, the class constant is also public and the property has been deprecated, to be removed in PHPCS 5.0.
Includes changing the array format from a list of strings to an associative array with the key and value for each entry holding the same string to allow for using isset() instead of in_array().
Modernize: Tokenizers\PHP: use class constant for constant array
Note: there are a couple of other properties in this class, which only contain static information. These, by nature, should be constants. however, those properties are overloading empty array properties from the abstract parent Tokenizer class, so I'm leaving those alone for now.
Modernize: AbstractVariableSniff: use class constant for constant array
As the property was in the public API, the class constant is also protected and the property has been deprecated, to be removed in PHPCS 5.0.
Modernize: Generic/CamelCapsFunctionName: use class constant for constant array
Modernize: Generic/various sniffs: use class constant for constant array
Modernize: Generic/SubversionProperties: use class constant for constant array
Modernize: PEAR/FileComment: use class constant for constant array
Note: this also affects the PEAR.Commenting.ClassComment sniff which extends this sniff.
That sniff doesn't access the deprecated property directly, but if other sniffs extend the ClassComment sniff, they may be affected.
Modernize: PEAR/ValidFunctionName: use class constant for constant array
Note: this also affects the Squiz.NamingConventions.ValidFunctionName sniff which extends this sniff.
That sniff doesn't access the deprecated property directly, but if other sniffs extend the Squiz ValidFunctionName sniff, they may be affected.
Modernize: Squiz/DisallowSizeFunctionsInLoops: use class constant for constant array
Suggested changelog entry
Deprecated:
-
PHP_CodeSniffer\Util\Common::$allowedTypes. UsePHP_CodeSniffer\Util\Common::ALLOWED_TYPESinstead. -
PHP_CodeSniffer\Tokenizers\PHP::$tstringContexts. UsePHP_CodeSniffer\Tokenizers\PHP::T_STRING_CONTEXTSinstead. -
PHP_CodeSniffer\Sniffs\AbstractVariableSniff::$phpReservedVars. UsePHP_CodeSniffer\Sniffs\AbstractVariableSniff::PHP_RESERVED_VARSinstead. -
PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::$magicMethods. UsePHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::MAGIC_METHODSinstead.- This also affects the
PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniffclass which extends theCamelCapsFunctionNameSniff.
- This also affects the
-
PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::$methodsDoubleUnderscore. UsePHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::DOUBLE_UNDERSCORE_METHODSinstead.- This also affects the
PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniffclass which extends theCamelCapsFunctionNameSniff.
- This also affects the
-
PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::$magicFunctions. UsePHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::MAGIC_FUNCTIONSinstead.- This also affects the
PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniffclass which extends theCamelCapsFunctionNameSniff.
- This also affects the
-
PHP_CodeSniffer\Standards\Generic\Sniffs\Files\ByteOrderMarkSniff::$bomDefinitions. UsePHP_CodeSniffer\Standards\Generic\Sniffs\Files\ByteOrderMarkSniff::BOM_DEFINITIONSinstead. -
PHP_CodeSniffer\Standards\Generic\Sniffs\Files\InlineHTMLSniff::$bomDefinitions. UsePHP_CodeSniffer\Standards\Generic\Sniffs\Files\InlineHTMLSniff::BOM_DEFINITIONSinstead. -
PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\CharacterBeforePHPOpeningTagSniff::$bomDefinitions. UsePHP_CodeSniffer\Standards\Generic\Sniffs\PHP\CharacterBeforePHPOpeningTagSniff::BOM_DEFINITIONSinstead. -
PHP_CodeSniffer\Standards\Generic\Sniffs\VersionControl\SubversionPropertiesSniff::$properties. UsePHP_CodeSniffer\Standards\Generic\Sniffs\VersionControl\SubversionPropertiesSniff::REQUIRED_PROPERTIESinstead. -
PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FileCommentSniff::$tags. UsePHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FileCommentSniff::EXPECTED_TAGSinstead.- This also affects the
PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\ClassCommentSniffclass which extends theFileCommentSniff.
- This also affects the
-
PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff::$magicMethods. UsePHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff::MAGIC_METHODSinstead.- This also affects the
PHP_CodeSniffer\Standards\Squiz\Sniffs\NamingConventions\ValidFunctionNameSniffclass which extends the PEARValidFunctionNameSniff.
- This also affects the
-
PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff::$magicFunctions. UsePHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff::MAGIC_FUNCTIONSinstead.- This also affects the
PHP_CodeSniffer\Standards\Squiz\Sniffs\NamingConventions\ValidFunctionNameSniffclass which extends the PEARValidFunctionNameSniff.
- This also affects the
-
PHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\DisallowSizeFunctionsInLoopsSniff::$forbiddenFunctions. UsePHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\DisallowSizeFunctionsInLoopsSniff::FORBIDDEN_FUNCTIONSinstead.