Skip to content

Commit

Permalink
Squiz/ScopeKeywordSpacing: minor efficiency tweak
Browse files Browse the repository at this point in the history
Bow out earlier when the sniff won't be able to action anything anyway (live coding/parse errors).
  • Loading branch information
jrfnl committed Jan 23, 2025
1 parent f08bd69 commit 0d0f8d4
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

if (isset($tokens[($stackPtr + 1)]) === false) {
$nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($nextNonWhitespace === false) {
// Parse error/live coding. Bow out.
return;
}

Expand Down Expand Up @@ -126,9 +128,6 @@ public function process(File $phpcsFile, $stackPtr)

if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
$spacing = 0;
} else if (isset($tokens[($stackPtr + 2)]) === false) {
// Parse error/live coding. Bow out.
return;
} else {
if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) {
$spacing = 'newline';
Expand Down

0 comments on commit 0d0f8d4

Please sign in to comment.