Skip to content

Commit

Permalink
Using isset() for performance (ref #2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Apr 23, 2018
1 parent 89484c2 commit 79d5fdf
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class ComparisonOperatorUsageSniff implements Sniff
* @var array
*/
private static $validOps = [
T_IS_IDENTICAL,
T_IS_NOT_IDENTICAL,
T_LESS_THAN,
T_GREATER_THAN,
T_IS_GREATER_OR_EQUAL,
T_IS_SMALLER_OR_EQUAL,
T_INSTANCEOF,
T_IS_IDENTICAL => true,
T_IS_NOT_IDENTICAL => true,
T_LESS_THAN => true,
T_GREATER_THAN => true,
T_IS_GREATER_OR_EQUAL => true,
T_IS_SMALLER_OR_EQUAL => true,
T_INSTANCEOF => true,
];

/**
Expand Down Expand Up @@ -157,15 +157,15 @@ public function process(File $phpcsFile, $stackPtr)

for ($i = $start; $i <= $end; $i++) {
$type = $tokens[$i]['code'];
if (in_array($type, array_keys(self::$invalidOps[$tokenizer])) === true) {
if (isset(self::$invalidOps[$tokenizer][$type]) === true) {
$error = 'Operator %s prohibited; use %s instead';
$data = [
$tokens[$i]['content'],
self::$invalidOps[$tokenizer][$type],
];
$phpcsFile->addError($error, $i, 'NotAllowed', $data);
$foundOps++;
} else if (in_array($type, self::$validOps) === true) {
} else if (isset(self::$validOps[$type]) === true) {
$foundOps++;
}

Expand Down

0 comments on commit 79d5fdf

Please sign in to comment.