Skip to content

Commit fd107c9

Browse files
authored
Don't report anything if the code is incomplete
1 parent ed0888c commit fd107c9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public function register()
5555
public function process(File $phpcsFile, $stackPtr)
5656
{
5757
$tokens = $phpcsFile->getTokens();
58+
if (isset($tokens[($stackPtr + 2)]) === false) {
59+
// Syntax error or live coding, bow out.
60+
return;
61+
}
5862

5963
$ignoreBefore = false;
6064
$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
@@ -79,14 +83,10 @@ public function process(File $phpcsFile, $stackPtr)
7983
$phpcsFile->recordMetric($stackPtr, 'Spacing before string concat', $before);
8084
}
8185

82-
if (isset($tokens[($stackPtr + 1)]) === false
83-
|| $tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE
84-
) {
86+
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
8587
$after = 0;
8688
} else {
87-
if (isset($tokens[($stackPtr + 2)]) === true
88-
&& $tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']
89-
) {
89+
if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) {
9090
$after = 'newline';
9191
} else {
9292
$after = $tokens[($stackPtr + 1)]['length'];

0 commit comments

Comments
 (0)