Skip to content

Commit 412ba54

Browse files
authored
Merge pull request #584 from Automattic/fix/sniff-efficiency
Performance: more selective sniffing for efficiency
2 parents 200dec1 + 0faf223 commit 412ba54

10 files changed

+18
-22
lines changed

WordPressVIPMinimum/Sniffs/Compatibility/ZoninatorSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ZoninatorSniff extends Sniff {
2222
* @return array(int)
2323
*/
2424
public function register() {
25-
return Tokens::$functionNameTokens;
25+
return [ T_STRING ];
2626
}
2727

2828

WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class CheckReturnValueSniff extends Sniff {
6060
* @return array(int)
6161
*/
6262
public function register() {
63-
return Tokens::$functionNameTokens;
63+
return [ T_STRING ];
6464
}
6565

6666
/**
@@ -86,7 +86,7 @@ public function process_token( $stackPtr ) {
8686
*/
8787
private function isFunctionCall( $stackPtr ) {
8888

89-
if ( in_array( $this->tokens[ $stackPtr ]['code'], Tokens::$functionNameTokens, true ) === false ) {
89+
if ( $this->tokens[ $stackPtr ]['code'] !== T_STRING ) {
9090
return false;
9191
}
9292

@@ -162,14 +162,14 @@ public function findDirectFunctionCalls( $stackPtr ) {
162162
$closeBracket = $this->tokens[ $openBracket ]['parenthesis_closer'];
163163

164164
$startNext = $openBracket + 1;
165-
$next = $this->phpcsFile->findNext( Tokens::$functionNameTokens, $startNext, $closeBracket, false, null, true );
165+
$next = $this->phpcsFile->findNext( T_STRING, $startNext, $closeBracket, false, null, true );
166166
while ( $next ) {
167167
if ( in_array( $this->tokens[ $next ]['content'], $this->catch[ $functionName ], true ) === true ) {
168168
$message = "`%s`'s return type must be checked before calling `%s` using that value.";
169169
$data = [ $this->tokens[ $next ]['content'], $functionName ];
170170
$this->phpcsFile->addError( $message, $next, 'DirectFunctionCall', $data );
171171
}
172-
$next = $this->phpcsFile->findNext( Tokens::$functionNameTokens, $next + 1, $closeBracket, false, null, true );
172+
$next = $this->phpcsFile->findNext( T_STRING, $next + 1, $closeBracket, false, null, true );
173173
}
174174
}
175175

@@ -269,7 +269,7 @@ public function findNonCheckedVariables( $stackPtr ) {
269269
foreach ( $callees as $callee ) {
270270
$notFunctionsCallee = array_key_exists( $callee, $this->notFunctions ) ? (array) $this->notFunctions[ $callee ] : [];
271271
// Check whether the found token is one of the function calls (or foreach call) we are interested in.
272-
if ( in_array( $this->tokens[ $nextFunctionCallWithVariable ]['code'], array_merge( Tokens::$functionNameTokens, $notFunctionsCallee ), true ) === true
272+
if ( in_array( $this->tokens[ $nextFunctionCallWithVariable ]['code'], array_merge( [ T_STRING ], $notFunctionsCallee ), true ) === true
273273
&& $this->tokens[ $nextFunctionCallWithVariable ]['content'] === $callee
274274
) {
275275
$this->addNonCheckedVariableError( $nextFunctionCallWithVariable, $variableName, $callee );
@@ -278,7 +278,7 @@ public function findNonCheckedVariables( $stackPtr ) {
278278

279279
$search = array_merge( Tokens::$emptyTokens, [ T_EQUAL ] );
280280
$next = $this->phpcsFile->findNext( $search, $nextVariableOccurrence + 1, null, true );
281-
if ( in_array( $this->tokens[ $next ]['code'], Tokens::$functionNameTokens, true ) === true
281+
if ( $this->tokens[ $next ]['code'] === T_STRING
282282
&& $this->tokens[ $next ]['content'] === $callee
283283
) {
284284
$this->addNonCheckedVariableError( $next, $variableName, $callee );

WordPressVIPMinimum/Sniffs/Hooks/AlwaysReturnInFilterSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AlwaysReturnInFilterSniff extends Sniff {
3030
* @return array(int)
3131
*/
3232
public function register() {
33-
return Tokens::$functionNameTokens;
33+
return [ T_STRING ];
3434
}
3535

3636
/**
@@ -130,7 +130,7 @@ private function processString( $stackPtr, $start = 0, $end = null ) {
130130
$callbackFunctionName = substr( $this->tokens[ $stackPtr ]['content'], 1, -1 );
131131

132132
$callbackFunctionPtr = $this->phpcsFile->findNext(
133-
Tokens::$functionNameTokens,
133+
T_STRING,
134134
$start,
135135
$end,
136136
false,

WordPressVIPMinimum/Sniffs/Hooks/PreGetPostsSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class PreGetPostsSniff extends Sniff {
2525
* @return array(int)
2626
*/
2727
public function register() {
28-
return Tokens::$functionNameTokens;
28+
return [ T_STRING ];
2929
}
3030

3131
/**
@@ -120,7 +120,7 @@ private function processString( $stackPtr ) {
120120
$callbackFunctionName = substr( $this->tokens[ $stackPtr ]['content'], 1, -1 );
121121

122122
$callbackFunctionPtr = $this->phpcsFile->findNext(
123-
Tokens::$functionNameTokens,
123+
T_STRING,
124124
0,
125125
null,
126126
false,
@@ -394,7 +394,7 @@ private function isWPQueryMethodCall( $stackPtr, $method = null ) {
394394
true
395395
);
396396

397-
return $next && in_array( $this->tokens[ $next ]['code'], Tokens::$functionNameTokens, true ) === true && $method === $this->tokens[ $next ]['content'];
397+
return $next && $this->tokens[ $next ]['code'] === T_STRING && $method === $this->tokens[ $next ]['content'];
398398
}
399399

400400
/**

WordPressVIPMinimum/Sniffs/Performance/CacheValueOverrideSniff.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CacheValueOverrideSniff extends Sniff {
2929
* @return array(int)
3030
*/
3131
public function register() {
32-
return Tokens::$functionNameTokens;
32+
return [ T_STRING ];
3333
}
3434

3535

@@ -97,10 +97,6 @@ public function process_token( $stackPtr ) {
9797
*/
9898
private function isFunctionCall( $stackPtr ) {
9999

100-
if ( in_array( $this->tokens[ $stackPtr ]['code'], Tokens::$functionNameTokens, true ) === false ) {
101-
return false;
102-
}
103-
104100
// Find the next non-empty token.
105101
$openBracket = $this->phpcsFile->findNext( Tokens::$emptyTokens, $stackPtr + 1, null, true );
106102

WordPressVIPMinimum/Sniffs/Performance/FetchingRemoteDataSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FetchingRemoteDataSniff extends Sniff {
2424
* @return array
2525
*/
2626
public function register() {
27-
return Tokens::$functionNameTokens;
27+
return [ T_STRING ];
2828
}
2929

3030
/**

WordPressVIPMinimum/Sniffs/Performance/TaxonomyMetaInOptionsSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TaxonomyMetaInOptionsSniff extends Sniff {
5151
* @return array
5252
*/
5353
public function register() {
54-
return Tokens::$functionNameTokens;
54+
return [ T_STRING ];
5555
}
5656

5757
/**

WordPressVIPMinimum/Sniffs/Security/ExitAfterRedirectSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ExitAfterRedirectSniff extends Sniff {
2424
* @return array
2525
*/
2626
public function register() {
27-
return Tokens::$functionNameTokens;
27+
return [ T_STRING ];
2828
}
2929

3030
/**

WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ProperEscapingFunctionSniff extends Sniff {
3535
* @return array
3636
*/
3737
public function register() {
38-
return Tokens::$functionNameTokens;
38+
return [ T_STRING ];
3939
}
4040

4141
/**

WordPressVIPMinimum/Sniffs/Security/StaticStrreplaceSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class StaticStrreplaceSniff extends Sniff {
2424
* @return array
2525
*/
2626
public function register() {
27-
return Tokens::$functionNameTokens;
27+
return [ T_STRING ];
2828
}
2929

3030
/**

0 commit comments

Comments
 (0)