squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

Tokenizer/PHP: bug fix for static typed properties with union/intersection types #3867

Closed jrfnl closed 9 months ago

jrfnl commented 1 year ago

Description

Just like the var keyword, the static keyword can also be used stand-alone with property declarations. https://3v4l.org/sbaDM

In that case, the tokenization of the | operator was not changed to T_TYPE_UNION and the & operator was not changed to T_TYPE_INTERSECTION as the static keyword can also be used in return type declarations, so was seen as part of the type declaration.

Fixed now by removing the T_STATIC token from the $allowed list before walking backwards from the operator.

Includes tests.

Note: this does mean that one test for the File::getMemberProperties() method needs to be changed, but as that was testing an illegal syntax anyway, I'm not concerned about making this change.

Suggested changelog entry

Tokenizer/PHP: union type and intersection type operators were not correctly tokenized as such for static typed properties without explicit visibility.

Types of changes

jrfnl commented 9 months ago

Closing as replaced by https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/78

jrfnl commented 8 months ago

FYI: this fix is included in today's PHP_CodeSniffer 3.8.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).