Skip to content

Commit 5ba0444

Browse files
committed
Squiz/ScopeKeywordSpacing: minor efficiency tweak
Bow out earlier when the sniff won't be able to action anything anyway (live coding/parse errors).
1 parent bdec83b commit 5ba0444

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public function process(File $phpcsFile, $stackPtr)
4444
{
4545
$tokens = $phpcsFile->getTokens();
4646

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

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

127129
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
128130
$spacing = 0;
129-
} else if (isset($tokens[($stackPtr + 2)]) === false) {
130-
// Parse error/live coding. Bow out.
131-
return;
132131
} else {
133132
if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) {
134133
$spacing = 'newline';

0 commit comments

Comments
 (0)