Skip to content

Commit 060338f

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 a7d8693 commit 060338f

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
@@ -109,6 +109,10 @@ public function process(File $phpcsFile, $stackPtr)
109109
];
110110
}
111111
}//end if
112+
113+
if (isset($tokens[$stackPtr]['scope_closer']) === true) {
114+
$stackPtr = $tokens[$stackPtr]['scope_closer'];
115+
}
112116
}//end if
113117

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

0 commit comments

Comments
 (0)