Skip to content

Commit

Permalink
Fix rare undefined offset errors in ConcatenationSpacingSniff
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thiemowmde authored Jun 17, 2020
1 parent 75ff420 commit ed0888c
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->recordMetric($stackPtr, 'Spacing before string concat', $before);
}

if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
if (isset($tokens[($stackPtr + 1)]) === false
|| $tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE
) {
$after = 0;
} else {
if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) {
if (isset($tokens[($stackPtr + 2)]) === true
&& $tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']
) {
$after = 'newline';
} else {
$after = $tokens[($stackPtr + 1)]['length'];
Expand Down

0 comments on commit ed0888c

Please sign in to comment.