-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
PHP 8.1: add support for enums #358
Merged
Merged
Conversation
This file contains 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
PHP 8.1 introduced a new type of OO structure: enumerations, which uses the `enum` keyword / `T_ENUM` token. Enums, like classes, interfaces and traits, are a closed scope structure, so the `Collections::closedScopes()` token array should include it. Refs: * https://wiki.php.net/rfc/enumerations
PHP 8.1 introduced a new type of OO structure: enums. Alike classes, constants can be declared in an enum too. This commit adds support for detecting whether a constant declared using the `const` keyword is within an enum structure to the `Scopes::isOOConstant()` method. Includes adding the `T_ENUM` token to the `Collections::ooConstantScopes()` token array. Refs: * https://wiki.php.net/rfc/enumerations
PHP 8.1 introduced a new type of OO structure: enums. Alike classes, methods can be declared in an enum. As the `Scopes::isOOMethod()` method uses the PHPCS based `[BC]Tokens::$ooScopeTokens` token array, in which `T_ENUM` was added in PHPCS 3.7.0, the `Scopes::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. Refs: * https://wiki.php.net/rfc/enumerations
PHP 8.1 introduced a new type of OO structure: enums. Unlike classes, properties are not allowed in enums. This commit adds tests to ensure the `Scopes::isOOProperty()` method handles this correctly. Refs: * https://wiki.php.net/rfc/enumerations
…h PHPCS / support enums PHP 8.1 introduced a new type of OO structure: 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: * https://wiki.php.net/rfc/enumerations * squizlabs/PHP_CodeSniffer 3482 Co-authored-by: Jaroslav Hanslík <kukulich@kukulich.cz>
…ith enum ... to verify the method correctly throws an exception.
… sync with PHPCS / add support for enums > An `enum` declaration can implement one or more interfaces. > > This commit updates the `File::findImplementedInterfaceNames()` method to allow it to find the interfaces implemented by an `enum` as well. > > Includes unit tests. Includes adding the `T_ENUM` token to the `Collections::ooCanImplement()` token array. Refs: * https://wiki.php.net/rfc/enumerations * squizlabs/PHP_CodeSniffer 3578
…r properties in enum Handle enums in the same way as interface properties (neither are supported by PHP). > Neither enums nor interfaces support properties being declared on them. > > This adjusts the `File::getMemberProperties() method to handle properties declared on an `enum` in the same way as properties declared on an `interface` were already being handled. Includes unit tests. Refs: * squizlabs/PHP_CodeSniffer 3577
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.
PHP 8.1 introduced a new type of OO structure: enumerations, which uses the
enum
keyword /T_ENUM
token.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
const
keyword is within an enum structure to theScopes::isOOConstant()
method.Includes adding the
T_ENUM
token 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::$ooScopeTokens
token array, in whichT_ENUM
was 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:
enum
support 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_ENUM
token 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:
enum
properties same as interface properties squizlabs/PHP_CodeSniffer#3577PHP 8.1 | Utils\UseStatements::getType(): update comment to document enum support