Skip to content

Commit 31df19b

Browse files
committed
Improve sniff check to see if it should bail early for a given function
1 parent 250969d commit 31df19b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
class UselessOverridingMethodSniff implements Sniff
2929
{
3030

31+
/**
32+
* List of class and trait tokens. Used to detect functions that
33+
* are part of a class, anon class or trait.
34+
*
35+
* @var array
36+
*/
37+
private $classAndTraitTokens = [
38+
T_CLASS => true,
39+
T_ANON_CLASS => true,
40+
T_TRAIT => true,
41+
];
42+
3143

3244
/**
3345
* Registers the tokens that this sniff wants to listen for.
@@ -64,7 +76,7 @@ public function process(File $phpcsFile, $stackPtr)
6476
$lastCondition = end($conditions);
6577

6678
// Skip functions that are not a method part of a class, anon class or trait.
67-
if (in_array($lastCondition, [T_CLASS, T_ANON_CLASS, T_TRAIT]) === false) {
79+
if (isset($this->classAndTraitTokens[$lastCondition]) === false) {
6880
return;
6981
}
7082

0 commit comments

Comments
 (0)