Skip to content

Commit bd0af7a

Browse files
committed
Generic/DuplicateClassName: performance fix
As things were, the sniff would unconditionally walk a complete file, making it one of the top 15 slowest sniffs. However, OO structures in PHP cannot be nested, so once we've found an OO declaration, we can skip to the end of it before continuing the token walking. See: https://3v4l.org/pbSTG This small tweak makes a significant difference in the sniff performance without any impact on the sniff results.
1 parent 2e98c74 commit bd0af7a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Standards/Generic/Sniffs/Classes/DuplicateClassNameSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public function process(File $phpcsFile, $stackPtr)
110110
];
111111
}
112112
}//end if
113+
114+
if (isset($tokens[$stackPtr]['scope_closer']) === true) {
115+
$stackPtr = $tokens[$stackPtr]['scope_closer'];
116+
}
113117
}//end if
114118

115119
$stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1));

0 commit comments

Comments
 (0)