Skip to content

Commit 12fcc3c

Browse files
committed
WP/DiscouragedConstants: update for PHPCS 4.0
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when checking the name of a given constants to see if it is one of the discouraged constants.
1 parent f3fc30e commit 12fcc3c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

WordPress/Sniffs/WP/DiscouragedConstantsSniff.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public function process_token( $stackPtr ) {
8484
}
8585

8686
/**
87-
* Process an arbitrary T_STRING token to determine whether it is one of the target constants.
87+
* Process an arbitrary T_STRING or T_NAME_FULLY_QUALIFIED token to determine whether it is one
88+
* of the target constants.
8889
*
8990
* @since 0.14.0
9091
*
@@ -95,6 +96,10 @@ public function process_token( $stackPtr ) {
9596
public function process_arbitrary_tstring( $stackPtr ) {
9697
$content = $this->tokens[ $stackPtr ]['content'];
9798

99+
if ( \T_NAME_FULLY_QUALIFIED === $this->tokens[ $stackPtr ]['code'] ) {
100+
$content = \ltrim( $content, '\\' );
101+
}
102+
98103
if ( ! isset( $this->discouraged_constants[ $content ] ) ) {
99104
return;
100105
}

0 commit comments

Comments
 (0)