-
-
Notifications
You must be signed in to change notification settings - Fork 73
Modernize: use class constants for constant arrays (public API) #1043
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
Draft
jrfnl
wants to merge
9
commits into
phpcs-4.0/feature/squiz-variablecomment-make-tagnotallowed-modular
Choose a base branch
from
phpcs-4.0/feature/modernize-use-constant-arrays-public-api
base: phpcs-4.0/feature/squiz-variablecomment-make-tagnotallowed-modular
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()`.
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.
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.
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.
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
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 ofin_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
theClassComment
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 SquizValidFunctionName
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_TYPES
instead.PHP_CodeSniffer\Tokenizers\PHP::$tstringContexts
. UsePHP_CodeSniffer\Tokenizers\PHP::T_STRING_CONTEXTS
instead.PHP_CodeSniffer\Sniffs\AbstractVariableSniff::$phpReservedVars
. UsePHP_CodeSniffer\Sniffs\AbstractVariableSniff::PHP_RESERVED_VARS
instead.PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::$magicMethods
. UsePHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::MAGIC_METHODS
instead.PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff
class which extends theCamelCapsFunctionNameSniff
.PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::$methodsDoubleUnderscore
. UsePHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::DOUBLE_UNDERSCORE_METHODS
instead.PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff
class which extends theCamelCapsFunctionNameSniff
.PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::$magicFunctions
. UsePHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff::MAGIC_FUNCTIONS
instead.PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff
class which extends theCamelCapsFunctionNameSniff
.PHP_CodeSniffer\Standards\Generic\Sniffs\Files\ByteOrderMarkSniff::$bomDefinitions
. UsePHP_CodeSniffer\Standards\Generic\Sniffs\Files\ByteOrderMarkSniff::BOM_DEFINITIONS
instead.PHP_CodeSniffer\Standards\Generic\Sniffs\Files\InlineHTMLSniff::$bomDefinitions
. UsePHP_CodeSniffer\Standards\Generic\Sniffs\Files\InlineHTMLSniff::BOM_DEFINITIONS
instead.PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\CharacterBeforePHPOpeningTagSniff::$bomDefinitions
. UsePHP_CodeSniffer\Standards\Generic\Sniffs\PHP\CharacterBeforePHPOpeningTagSniff::BOM_DEFINITIONS
instead.PHP_CodeSniffer\Standards\Generic\Sniffs\VersionControl\SubversionPropertiesSniff::$properties
. UsePHP_CodeSniffer\Standards\Generic\Sniffs\VersionControl\SubversionPropertiesSniff::REQUIRED_PROPERTIES
instead.PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FileCommentSniff::$tags
. UsePHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FileCommentSniff::EXPECTED_TAGS
instead.PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\ClassCommentSniff
class which extends theFileCommentSniff
.PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff::$magicMethods
. UsePHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff::MAGIC_METHODS
instead.PHP_CodeSniffer\Standards\Squiz\Sniffs\NamingConventions\ValidFunctionNameSniff
class which extends the PEARValidFunctionNameSniff
.PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff::$magicFunctions
. UsePHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff::MAGIC_FUNCTIONS
instead.PHP_CodeSniffer\Standards\Squiz\Sniffs\NamingConventions\ValidFunctionNameSniff
class which extends the PEARValidFunctionNameSniff
.PHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\DisallowSizeFunctionsInLoopsSniff::$forbiddenFunctions
. UsePHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\DisallowSizeFunctionsInLoopsSniff::FORBIDDEN_FUNCTIONS
instead.