From 58836a8ea79701c91dca0387aa9420a2b77a975b Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Fri, 15 Aug 2025 15:21:55 -0300 Subject: [PATCH 1/2] ConstantsHelper::is_use_of_global_constant(): do not treat `use const` alias as global constant usage This method was incorrectly identifying a constant alias as a global constant. This change aligns this method with how the sibling method in PHPCompatibility behaves (https://github.com/PHPCompatibility/PHPCompatibility/blob/6e10469b0f3827862b37df2ac2b7ec4580ce888f/PHPCompatibility/Helpers/MiscHelper.php#L45). --- WordPress/Helpers/ConstantsHelper.php | 1 + WordPress/Tests/WP/DiscouragedConstantsUnitTest.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Helpers/ConstantsHelper.php b/WordPress/Helpers/ConstantsHelper.php index 6decbb4010..320c6312f8 100644 --- a/WordPress/Helpers/ConstantsHelper.php +++ b/WordPress/Helpers/ConstantsHelper.php @@ -79,6 +79,7 @@ public static function is_use_of_global_constant( File $phpcsFile, $stackPtr ) { \T_INSTANCEOF => true, \T_INSTEADOF => true, \T_GOTO => true, + \T_AS => true, ); $tokens_to_ignore += Tokens::$ooScopeTokens; $tokens_to_ignore += Collections::objectOperators(); diff --git a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php index e27fd838c2..57ea154594 100644 --- a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php +++ b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php @@ -49,7 +49,6 @@ public function getWarningList() { 60 => 1, 61 => 1, 63 => 1, - 64 => 1, 66 => 1, 67 => 1, 71 => 1, From ea416f0dbdf3dac182a20a05d0c7c5f576c666c3 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Wed, 3 Sep 2025 19:54:24 -0300 Subject: [PATCH 2/2] Add comment clarifying that this specific test is now an exception in the group --- WordPress/Tests/WP/DiscouragedConstantsUnitTest.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.inc b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.inc index ea8ae72524..919fdd2fcb 100644 --- a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.inc +++ b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.inc @@ -61,7 +61,7 @@ echo BACKGROUND_COLOR; echo BACKGROUND_IMAGE; use const STYLESHEETPATH as SSP; -use const ABC as STYLESHEETPATH; +use const ABC as STYLESHEETPATH; // This is ok, as `STYLESHEETPATH` is not a global constant here. switch( STYLESHEETPATH ) { case STYLESHEETPATH: