Skip to content

Commit 46bddcd

Browse files
authored
Helper::findVariableScope(): performance tweak (#139)
Using `isset()` is significantly faster than a call to `in_array()` and as the PHPCS native `Tokens` class already contains a property representing the tokens being checked for here, we may as well use it.
1 parent cf89bb2 commit 46bddcd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

VariableAnalysis/Lib/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public static function findVariableScope(File $phpcsFile, $stackPtr) {
316316
if (($scopeCode === T_FUNCTION) || ($scopeCode === T_CLOSURE)) {
317317
return $scopePtr;
318318
}
319-
if (in_array($scopeCode, [T_CLASS, T_ANON_CLASS, T_INTERFACE, T_TRAIT])) {
319+
if (isset(Tokens::$ooScopeTokens[$scopeCode]) === true) {
320320
$in_class = true;
321321
}
322322
}

0 commit comments

Comments
 (0)