Skip to content

Commit

Permalink
Don't report anything if the code is incomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
thiemowmde authored Jun 17, 2020
1 parent ed0888c commit fd107c9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function register()
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if (isset($tokens[($stackPtr + 2)]) === false) {
// Syntax error or live coding, bow out.
return;
}

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

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

0 comments on commit fd107c9

Please sign in to comment.