Skip to content
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 | File::getMethodProperties(): support mixed type and union types #3010

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jul 7, 2020

PHP 8.0 will introduce a new pseudo-type mixed as well as union types.

This PR adds tests for these to the File::getMethodProperties() method and makes minor changes to the method to allow for supporting these new type declarations.

Includes a change to the PHP tokenizer to make sure that the array keyword in union return types is changed to T_STRING.

Refs:

👉 Important: all sniffs using this method will need to be checked to see if they use the return_type index and if so, if the check being done needs to take union types into account.

Partially addresses #2968

jrfnl added 2 commits July 7, 2020 09:14
No changes needed to the actual method, the return type is already handled correctly.
`array` keywords used as return types in PHP 8 union types would only be correctly changed to `T_STRING` if they were the first type in the union.

Fixed now.

Includes adding `T_STATIC` to the array of allowed tokens. While previously it wasn't an issue that the token was not includes in the array, it is necessary for the token to be there to support union types.
@jrfnl jrfnl mentioned this pull request Jul 7, 2020
jrfnl added 2 commits July 7, 2020 22:03
PHP 8 introduces union types.

This adds support for union types to the `File::getMethodProperties()` method.

Includes extensive unit tests.

Ref: https://wiki.php.net/rfc/union_types_v2
@jrfnl jrfnl force-pushed the feature/2968-getmethodproperties-support-php8-mixed-and-union-types branch from faabb0e to dc0fe93 Compare July 7, 2020 20:05
@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 12, 2020

Test build which includes PR #3014 which confirms that the build for this PR would pass on PHP 8/nightly: https://travis-ci.com/github/jrfnl/PHP_CodeSniffer/jobs/360290484

@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 15, 2020

Closing - this PR is partially replaced by PR #3018 (mixed type) and will for the remainder be replaced by a subsequent PR addressing union types. These have to be pulled in turn as they both add unit tests to the same files. See issue #2968 for the background of why the PR(s) are replaced.

@jrfnl jrfnl closed this Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant