Skip to content

Commit

Permalink
Generic/DuplicateClassName: performance fix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrfnl committed Oct 30, 2024
1 parent a7d8693 commit 060338f
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public function process(File $phpcsFile, $stackPtr)
];
}
}//end if

if (isset($tokens[$stackPtr]['scope_closer']) === true) {
$stackPtr = $tokens[$stackPtr]['scope_closer'];
}
}//end if

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

0 comments on commit 060338f

Please sign in to comment.