Skip to content

Commit

Permalink
Merge pull request #2276 from WordPress/feature/preffixallglobals-bug…
Browse files Browse the repository at this point in the history
…fix-function-compare-case-insensitive

NamingConventions/PrefixAllGlobals: make the "is PHP native polyfill ?" check case-insensitive
  • Loading branch information
dingo-d authored Jul 4, 2023
2 parents 110408c + 574b7bb commit cd8c4f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public function register() {
// Get a list of all PHP native functions.
$all_functions = get_defined_functions();
$this->built_in_functions = array_flip( $all_functions['internal'] );
$this->built_in_functions = array_change_key_case( $this->built_in_functions, \CASE_LOWER );

// Set the sniff targets.
$targets = array(
Expand Down Expand Up @@ -413,7 +414,8 @@ public function process_token( $stackPtr ) {
}

$item_name = FunctionDeclarations::getName( $this->phpcsFile, $stackPtr );
if ( isset( $this->built_in_functions[ $item_name ] ) ) {
$item_lc = strtolower( $item_name );
if ( isset( $this->built_in_functions[ $item_lc ] ) ) {
// Backfill for PHP native function.
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,11 @@ function acronym_only_check_global_statement_in_current_scope() {
$something = 'value'; // OK, global statement is in different scope.
}

/*
* Safeguard that function name comparisons for PHP native function polyfills are done case-insensitively.
*/
if ( function_exists( 'stripos' ) ) {
function striPos() {}
}

// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[]

0 comments on commit cd8c4f2

Please sign in to comment.