PHP 8.1: add support for enums #358
Merged
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.
PHP 8.1 introduced a new type of OO structure: enumerations, which uses the
enumkeyword /T_ENUMtoken.Refs:
PHP 8.1 | Collections::closedScopes(): add the T_ENUM token
Enums, like classes, interfaces and traits, are a closed scope structure, so the
Collections::closedScopes()token array should include it.PHP 8.1 | Scopes::isOOConstant(): add support for constants in enums
Alike classes, constants can be declared in an enum too.
This commit adds support for detecting whether a constant declared using the
constkeyword is within an enum structure to theScopes::isOOConstant()method.Includes adding the
T_ENUMtoken to theCollections::ooConstantScopes()token array.PHP 8.1 | Scopes::isOOMethod(): add support for enums
Alike classes, methods can be declared in an enum.
As the
Scopes::isOOMethod()method uses the PHPCS based[BC]Tokens::$ooScopeTokenstoken array, in whichT_ENUMwas added in PHPCS 3.7.0, theScopes::isOOMethod()method will correctly recognize methods within enums as OO methods.This commit updates the documentation to indicate support for enums + adds tests to safeguard support.
PHP 8.1 | Scopes::isOOProperty(): add tests for enums
Unlike classes, properties are not allowed in enums.
This commit adds tests to ensure the
Scopes::isOOProperty()method handles this correctly.PHP 8.1 | BCFile/ObjectDeclarations::get[Declaration]Name(): sync with PHPCS / support enums
Enums are a named structure, so the
BCFile/ObjectDeclarations::get[Declaration]Name()method should handle this correctly.This commit syncs in the changes from upstream for the same.
Refs:
enumsupport to sniffs squizlabs/PHP_CodeSniffer#3482PHP 8.1 | BCFile/ObjectDeclarations::getClassProperties(): add test with enum
... to verify the method correctly throws an exception.
PHP 8.1 | BCFile/ObjectDeclarations::findImplementedInterfaceNames(): sync with PHPCS / add support for enums
Includes adding the
T_ENUMtoken to theCollections::ooCanImplement()token array.Refs:
PHP 8.1 | BCFile/Variables::getMemberProperties(): throw exception for properties in enum
Handle enums in the same way as interface properties (neither are supported by PHP).
Includes unit tests.
Refs:
enumproperties same as interface properties squizlabs/PHP_CodeSniffer#3577PHP 8.1 | Utils\UseStatements::getType(): update comment to document enum support