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: more context sensitive keyword fixes #3797

Closed jrfnl closed 1 year ago

jrfnl commented 1 year ago

PHPCS re-tokenizes the self, parent, true, false and null keywords to a PHPCS native token.

This re-tokenization did not take the following situations into account:

Additionally, the PHP native T_STATIC token would not be (re-)tokenized to T_STRING when used as a function call, though it was tokenized correctly when used as a method call. While using the static keyword for a global function declaration is illegal in PHP, the tokenization in PHPCS should still be consistent.

This commit fixes those issues.

Includes additional unit tests.

These issues were discovered while investigating issue PHPCompatibility/PHPCompatibility#1489

jrfnl commented 1 year ago

Note: I've updated the commit to contain yet more unit tests.

jrfnl commented 9 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).