Skip to content

Conversation

@jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Nov 2, 2020

File::getMethodProperties(): add new return_type_end_token index to return value

With union types, even non-class return types may consist of multiple tokens, so having access to the stackPtr for the exact end of the return type becomes relevant for sniffs which include fixers.

This commit adds a return_type_end_token index key to the array return value of the File::getMethodProperties() method.

Generic/LowerCaseType: minor tweak to a unit test

... to verify and safeguard that spacing within a type cast is not touched by the sniff.

Generic/LowerCaseType: refactor [1] - move array to property

Move the $phpTypes array to a property and add the new types introduced in PHP 8.0 to it.

Generic/LowerCaseType: refactor [2] - remove duplicate code

Extract duplicate code out to a separate method and call the method instead.

PHP 8.0 | Generic/LowerCaseType: refactor [3] - allow for union types

Allow for union types, as introduced in PHP 8.0, in return and parameter type declarations.

Includes unit tests.

PHP 7.4 | Generic/LowerCaseType: add support for typed properties

PHP 7.4 introduced typed properties, but this sniff did not examine those yet.

Includes unit tests.

Partially fixes #2968.

jrfnl added 6 commits November 2, 2020 07:08
… return value

With union types, even non-class return types may consist of multiple tokens, so having access to the stackPtr for the exact end of the return type becomes relevant for sniffs which include fixers.

This commit adds a `return_type_end_token` index key to the array return value of the `File::getMethodProperties()` method.
... to verify and safeguard that spacing within a type cast is not touched by the sniff.
Move the `$phpTypes` array to a property and add the new types introduced in PHP 8.0 to it.
Extract duplicate code out to a separate method and call the method instead.
Allow for union types, as introduced in PHP 8.0, in return and parameter type declarations.

Includes unit tests.
PHP 7.4 introduced typed properties, but this sniff did not examine those yet.

Includes unit tests.
@gsherwood gsherwood added this to the 3.6.0 milestone Nov 2, 2020
gsherwood added a commit that referenced this pull request Nov 2, 2020
@gsherwood gsherwood merged commit b8c5436 into squizlabs:master Nov 2, 2020
@gsherwood
Copy link
Member

Thanks a lot for all the changes, and for breaking up the commits on this one. Made is much easier to review.

@jrfnl jrfnl deleted the feature/generic-lowercasetype-union-types-php8 branch November 2, 2020 21:49
@jrfnl
Copy link
Contributor Author

jrfnl commented Nov 2, 2020

You're welcome.

Made is much easier to review.

Which is exactly why I do it ;-)

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.

Support PHP 8's mixed type

2 participants