private function fixWhiteSpaceAroundSequence(Tokens $tokens, $endIndex)
{
$lineEnding = $this->whitespacesConfig->getLineEnding();
// start index of the sequence is always 1 here, 0 is always open tag
// transform "<?php\n" to "<?php " if needed
if (false !== strpos($tokens[0]->getContent(), "\n")) {
$tokens[0]->setContent(trim($tokens[0]->getContent()) . ' ');
}
if ($endIndex === count($tokens) - 1) {
return;
// no more tokens afters sequence, single_blank_line_at_eof might add a line
}
if (!$tokens[1 + $endIndex]->isWhitespace()) {
$tokens->insertAt(1 + $endIndex, new Token(array(T_WHITESPACE, $lineEnding)));
return;
}
$content = $tokens[1 + $endIndex]->getContent();
if (false !== strpos($content, "\n")) {
return;
}
$tokens[1 + $endIndex]->setContent($lineEnding . ltrim($content));
}