-
-
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.0 | Add support for union types #168
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
…eTokens() Deprecate the `$parameterTypeTokens` property in favour of a new `Collections::parameterTypeTokens()` method. PHPCS is expected to introduce a new `T_TYPE_UNION` token. As that token would not always be available, a property can't handle this. In anticipation of the introduction of the new token, I'm deprecating the `Collections::$parameterTypeTokens` property straight away to prevent BC breaks at a later point. Includes adding unit tests for the new method.
…n types Includes adjusted unit test.
…okens() Deprecate the `$propertyTypeTokens` property in favour of a new `Collections::propertyTypeTokens()` method. PHPCS is expected to introduce a new `T_TYPE_UNION` token. As that token would not always be available, a property can't handle this. In anticipation of the introduction of the new token, I'm deprecating the `Collections::$propertyTypeTokens` property straight away to prevent BC breaks at a later point. Includes adding unit tests for the new method.
… types Includes adjusted unit test.
Deprecate the `$returnTypeTokens` property in favour of a new `Collections::returnTypeTokens()` method. PHPCS is expected to introduce a new `T_TYPE_UNION` token. As that token would not always be available, a property can't handle this. In anticipation of the introduction of the new token, I'm deprecating the `Collections::$returnTypeTokens` property straight away to prevent BC breaks at a later point. Includes adding unit tests for the new method.
…ypes In addition to the other tokens needed to support union types, the `returnTypeTokens[BC]()` methods also needs the `T_ARRAY` token as the `array` keyword in union type return types is not always correctly re-tokenized to `T_STRING`. A change to the PHPCS tokenizer to mitigate this will be pulled upstream, but until that PR has been merged, `T_ARRAY` will continue to be needed. This changes the versions supported by the `returnTypeTokens()` method from "minimum PHPCS 3.5.4" to "minimum 3.3.0", which also brings the method more in line with the `parameterTypeTokens()` and the `propertyTypeTokens()` methods. Includes adjusted unit tests.
…types This commit adds support for union types to the `FunctionDeclarations::getParameters()` method. Changes along the same lines as included in this PR will also be pulled upstream to PHPCS itself. Once the upstream PR has been merged, those changes will also be applied to the `BCFile::getMethodParameters()` method. Includes extensive unit tests. Ref: https://wiki.php.net/rfc/union_types_v2
…r PHP 8 "union" types The commit which added union type support to the `Collections::returnTypeTokens[BC]()` methods implicitly added support for union types to the `FunctionDeclarations::getProperties()` method. This commit adds extensive unit tests to safeguard this support. The same commit also _silently_ added support for union types to the `BCFile::getMethodProperties()` method. Union types are not supported yet in PHPCS itself and until they are, the fact that the `BCFile::getMethodProperties()` method supports them should be regarded as an artefact and not as official support.
… 8 "union" types The commit which added union type support to the `Collections::propertyTypeTokens[BC]()` methods implicitly added support for union types to the `Variables::getMemberProperties()` method. This commit adds extensive unit tests to safeguard this support. The same commit also _silently_ added support for union types to the `BCFile::getMemberProperties()` method. Union types are not supported yet in PHPCS itself and until they are, the fact that the `BCFile::getMemberProperties()` method supports them should be regarded as an artefact and not as official support.
…for union types Adds tests, same as wil be pulled upstream, to the tests for the `FunctionDeclarations::isArrowFunction()` and the `FunctionDeclarations::getArrowFunctionOpenClose()` methods to verify and safeguard support for arrow functions using union type declarations.
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.
This PR effectively adds support for union type declarations to all the PHPCSUtils native functionality.
FunctionDeclarations::getParameters()
FunctionDeclarations::getProperties()
Variables::getMemberProperties()
FunctionDeclarations::isArrowFunction()
FunctionDeclaraions::getArrowFunctionOpenClose()
In anticipation of how these changes will be pulled upstream, the
Collections::$parameterTypeTokens
,Collections::$propertyTypeTokens
andCollections::$returnTypeTokens
properties are now deprecated in favour of methods by the same name, i.e.Collections::parameterTypeTokens()
,Collections::propertyTypeTokens()
andCollections::returnTypeTokens()
.The deprecated properties will be removed before the final
1.0.0
version of PHPCSUtils is tagged.The changes are accompanied by ample unit tests.
Ref: https://wiki.php.net/rfc/union_types_v2
Commit Details
Collections::propertyTypeTokensBC(): uncouple from the parameterTypeTokensBC() method
Collections: deprecate $parameterTypeTokens in favour of parameterTypeTokens()
Deprecate the
$parameterTypeTokens
property in favour of a newCollections::parameterTypeTokens()
method.PHPCS is expected to introduce a new
T_TYPE_UNION
token. As that token would not always be available, a property can't handle this.In anticipation of the introduction of the new token, I'm deprecating the
Collections::$parameterTypeTokens
property straight away to prevent BC breaks at a later point.Includes adding unit tests for the new method.
PHP 8.0 | Collection::parameterTypeTokensBC: add support for union types
Includes adjusted unit test.
Collections: deprecate $propertyTypeTokens in favour of propertyTypeTokens()
Deprecate the
$propertyTypeTokens
property in favour of a newCollections::propertyTypeTokens()
method.PHPCS is expected to introduce a new
T_TYPE_UNION
token. As that token would not always be available, a property can't handle this.In anticipation of the introduction of the new token, I'm deprecating the
Collections::$propertyTypeTokens
property straight away to prevent BC breaks at a later point.Includes adding unit tests for the new method.
PHP 8.0 | Collection::propertyTypeTokensBC: add support for union types
Includes adjusted unit test.
Collections: deprecate $returnTypeTokens in favour of returnTypeTokens()
Deprecate the
$returnTypeTokens
property in favour of a newCollections::returnTypeTokens()
method.PHPCS is expected to introduce a new
T_TYPE_UNION
token. As that token would not always be available, a property can't handle this.In anticipation of the introduction of the new token, I'm deprecating the
Collections::$returnTypeTokens
property straight away to prevent BC breaks at a later point.Includes adding unit tests for the new method.
PHP 8.0 | Collection::returnTypeTokensBC: add support for union types
In addition to the other tokens needed to support union types, the
returnTypeTokens[BC]()
methods also needs theT_ARRAY
token as thearray
keyword in union type return types is not always correctly re-tokenized toT_STRING
.A change to the PHPCS tokenizer to mitigate this will be pulled upstream, but until that PR has been merged,
T_ARRAY
will continue to be needed.This changes the versions supported by the
returnTypeTokens()
method from "minimum PHPCS 3.5.4" to "minimum 3.3.0", which also brings the method more in line with theparameterTypeTokens()
and thepropertyTypeTokens()
methods.Includes adjusted unit tests.
FunctionDeclarations::getParameters(): add support for PHP 8 "union" types
This commit adds support for union types to the
FunctionDeclarations::getParameters()
method.Changes along the same lines as included in this PR will also be pulled upstream to PHPCS itself. Once the upstream PR has been merged, those changes will also be applied to the
BCFile::getMethodParameters()
method.Includes extensive unit tests.
Ref: https://wiki.php.net/rfc/union_types_v2
FunctionDeclarations::getProperties(): add tests verifying support for PHP 8 "union" types
The commit which added union type support to the
Collections::returnTypeTokens[BC]()
methods implicitly added support for union types to theFunctionDeclarations::getProperties()
method.This commit adds extensive unit tests to safeguard this support.
The same commit also silently added support for union types to the
BCFile::getMethodProperties()
method. Union types are not supported yet in PHPCS itself and until they are, the fact that theBCFile::getMethodProperties()
method supports them should be regarded as an artefact and not as official support.Variables::getMemberProperties(): add tests verifying support for PHP 8 "union" types
The commit which added union type support to the
Collections::propertyTypeTokens[BC]()
methods implicitly added support for union types to theVariables::getMemberProperties()
method.This commit adds extensive unit tests to safeguard this support.
The same commit also silently added support for union types to the
BCFile::getMemberProperties()
method. Union types are not supported yet in PHPCS itself and until they are, the fact that theBCFile::getMemberProperties()
method supports them should be regarded as an artefact and not as official support.FunctionDeclarations::isArrowFunction(): add tests verifying support for union types
Adds tests, same as wil be pulled upstream, to the tests for the
FunctionDeclarations::isArrowFunction()
and theFunctionDeclarations::getArrowFunctionOpenClose()
methods to verify and safeguard support for arrow functions using union type declarations.Docs: update "nullable_type" comments to clarify meaning