Skip to content

Instantly share code, notes, and snippets.

@grappler
Created June 10, 2018 18:44
Show Gist options
  • Save grappler/10dc57b4b3ab71a35e2fe925ef4da1ec to your computer and use it in GitHub Desktop.
Save grappler/10dc57b4b3ab71a35e2fe925ef4da1ec to your computer and use it in GitHub Desktop.
diff --git a/WordPress/Sniffs/Theme/NoDeregisterCoreScriptSniff.php b/WordPress/Sniffs/Theme/NoDeregisterCoreScriptSniff.php
index 9fffd0cf..9659bcfb 100644
--- a/WordPress/Sniffs/Theme/NoDeregisterCoreScriptSniff.php
+++ b/WordPress/Sniffs/Theme/NoDeregisterCoreScriptSniff.php
@@ -170,22 +170,23 @@ class NoDeregisterCoreScriptSniff extends AbstractFunctionParameterSniff {
return;
}
- // More extensive check to prevent people circumventing the sniff.
- $text = '';
- $found_variable_token = false;
+ $found_variable_token = $this->phpcsFile->findNext(
+ array( T_VARIABLE, T_STRING ),
+ $parameters[1]['start'],
+ $parameters[1]['end'] + 1
+ );
+
+ if ( false !== $found_variable_token ) {
+ $this->throw_variable_handle_warning( $stackPtr, array( $matched_content ) );
+ return;
+ }
+ // More extensive check to prevent people circumventing the sniff.
+ $text = '';
for ( $i = $parameters[1]['start']; $i <= $parameters[1]['end']; $i++ ) {
- if ( isset( Tokens::$stringTokens[ $this->tokens[ $i ]['code'] ] ) === false ) {
- if ( T_VARIABLE === $this->tokens[ $i ]['code']
- || T_STRING === $this->tokens[ $i ]['code']
- ) {
- $found_variable_token = true;
- }
-
- continue;
+ if ( isset( Tokens::$stringTokens[ $this->tokens[ $i ]['code'] ] ) ) {
+ $text .= $this->strip_quotes( $this->tokens[ $i ]['content'] );
}
-
- $text .= $this->strip_quotes( $this->tokens[ $i ]['content'] );
}
if ( isset( $this->target_functions[ $matched_content ][ $text ] ) ) {
@@ -193,9 +194,6 @@ class NoDeregisterCoreScriptSniff extends AbstractFunctionParameterSniff {
return;
}
- if ( true === $found_variable_token ) {
- $this->throw_variable_handle_warning( $stackPtr, array( $matched_content ) );
- }
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment