public function ensureWhitespaceAtIndex($index, $indexOffset, $whitespace)
{
$removeLastCommentLine = function (Token $token, $indexOffset) {
// because comments tokens are greedy and may consume single \n if we are putting whitespace after it let trim that \n
if (1 === $indexOffset && $token->isComment()) {
$token->setContent(preg_replace("#\r\n\$|\n\$#", '', $token->getContent(), 1));
}
};
if ($this[$index]->isWhitespace()) {
$removeLastCommentLine($this[$index - 1], $indexOffset);
$this->overrideAt($index, array(T_WHITESPACE, $whitespace));
return false;
}
$removeLastCommentLine($this[$index], $indexOffset);
$this->insertAt($index + $indexOffset, array(new Token(array(T_WHITESPACE, $whitespace))));
return true;
}