diff --git a/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php b/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php index 6966ce36b3..763e7863ca 100644 --- a/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php +++ b/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php @@ -110,23 +110,27 @@ public function process(File $phpcsFile, $stackPtr) } for ($i = 0; $i < $phpcsFile->numTokens; $i++) { - if (isset($tokens[($i + 1)]) === false - || $tokens[($i + 1)]['line'] > $tokens[$i]['line'] + if (isset($tokens[($i + 1)]) === true + && $tokens[($i + 1)]['line'] <= $tokens[$i]['line'] ) { - // Token is the last on a line. - if (isset($tokens[$i]['orig_content']) === true) { - $tokenContent = $tokens[$i]['orig_content']; - } else { - $tokenContent = $tokens[$i]['content']; - } - - if ($tokenContent === '') { - // Special case for JS/CSS close tag. - continue; - } - - $newContent = rtrim($tokenContent, "\r\n"); - $newContent .= $eolChar; + continue; + } + + // Token is the last on a line. + if (isset($tokens[$i]['orig_content']) === true) { + $tokenContent = $tokens[$i]['orig_content']; + } else { + $tokenContent = $tokens[$i]['content']; + } + + if ($tokenContent === '') { + // Special case for JS/CSS close tag. + continue; + } + + $newContent = rtrim($tokenContent, "\r\n"); + $newContent .= $eolChar; + if ($tokenContent !== $newContent) { $phpcsFile->fixer->replaceToken($i, $newContent); } }//end for