diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 887d0408c9..74191df878 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -626,6 +626,11 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p return; } + if ( strpos( $raw_content, '\\' ) !== false ) { + // Namespaced or unreachable constant. + return; + } + $data = array( 'Global constants defined' ); $error_code = 'NonPrefixedConstantFound'; } else { diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc index d8562e2eb3..2c9ca83f96 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc @@ -13,3 +13,6 @@ const SOME_CONSTANT = 'value'; class Example {} interface I_Example {} trait T_Example {} + +// Issue #1056. +define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ ); diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.inc b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.inc index cc258a131a..44d8dbff69 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.inc +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.inc @@ -306,3 +306,15 @@ do_action( 'acronym-action' ); // OK. apply_filters( 'acronym/filter', $var ); // OK. do_action( "acronym-action-{$acronym_filter_var}" ); // OK. apply_filters( 'acronym/filter-' . $acronym_filter_var ); // OK. + +// Issue #1056. +define( 'SomeNameSpace\PLUGIN_FILE', __FILE__ ); // OK. +define( '\OtherNameSpace\PLUGIN_FILE', __FILE__ ); // OK. +// OK: unreachable constants. +define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ ); +define( '\PLUGIN_FILE', __FILE__ ); + +namespace Testing { + define( 'MY' . __NAMESPACE__, __FILE__ ); // Error, not actually namespaced. + define( 'MY\\' . __NAMESPACE__, __FILE__ ); // OK, even though strangely setup, the constant is in a namespace. +} diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php index 108471574b..d23bc645e7 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php @@ -57,6 +57,7 @@ public function getErrorList( $testFile = 'PrefixAllGlobalsUnitTest.inc' ) { 230 => ( function_exists( '\array_column' ) ) ? 0 : 1, 234 => ( defined( '\E_DEPRECATED' ) ) ? 0 : 1, 238 => ( class_exists( '\IntlTimeZone' ) ) ? 0 : 1, + 318 => 1, ); case 'PrefixAllGlobalsUnitTest.1.inc':