Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 18, 2024
1 parent ae1dc65 commit 4acbce1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Fixer/PhpTag/BlankLineAfterOpeningTagFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
$tokens[$openTagIndex] = new Token([$token->getId(), rtrim($token->getContent()).$lineEnding]);
}

if (isset($tokens[$openTagIndex + 1]) && !str_contains($tokens[$openTagIndex + 1]->getContent(), "\n")) {
if ($tokens[$openTagIndex + 1]->isWhitespace()) {
$tokens[$openTagIndex + 1] = new Token([T_WHITESPACE, $lineEnding.$tokens[$openTagIndex + 1]->getContent()]);
$newLineIndex = $openTagIndex + 1;
if (isset($tokens[$newLineIndex]) && !str_contains($tokens[$newLineIndex]->getContent(), "\n")) {
if ($tokens[$newLineIndex]->isWhitespace()) {
$tokens[$newLineIndex] = new Token([T_WHITESPACE, $lineEnding.$tokens[$newLineIndex]->getContent()]);
} else {
$tokens->insertAt($openTagIndex + 1, new Token([T_WHITESPACE, $lineEnding]));
$tokens->insertAt($newLineIndex, new Token([T_WHITESPACE, $lineEnding]));
}
}
}
Expand Down

0 comments on commit 4acbce1

Please sign in to comment.