Skip to content

Commit 8fb3b44

Browse files
thiemowmdegsherwood
authored andcommitted
Fix rare undefined offset errors in ConcatenationSpacingSniff
This can happen when PHPCS runs on a file that is currently being worked on, but not yet completed. The file might end with a dot. We can not assume there are always 2 more tokens after a dot.
1 parent dedda1e commit 8fb3b44

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

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

Lines changed: 4 additions & 0 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);

0 commit comments

Comments
 (0)