public function fix(\SplFileInfo $file, Tokens $tokens)
{
if (null === $this->headerComment) {
throw new RequiredFixerConfigurationException($this->getName(), 'Configuration is required.');
}
// figure out where the comment should be placed
$headerNewIndex = $this->findHeaderCommentInsertionIndex($tokens);
// check if there is already a comment
$headerCurrentIndex = $this->findHeaderCommentCurrentIndex($tokens, $headerNewIndex - 1);
if (null === $headerCurrentIndex) {
if ('' === $this->headerComment) {
return;
// header not found and none should be set, return
}
$this->insertHeader($tokens, $headerNewIndex);
} elseif ($this->headerComment !== $tokens[$headerCurrentIndex]->getContent()) {
$tokens->clearTokenAndMergeSurroundingWhitespace($headerCurrentIndex);
if ('' === $this->headerComment) {
return;
// header found and cleared, none should be set, return
}
$this->insertHeader($tokens, $headerNewIndex);
} else {
$headerNewIndex = $headerCurrentIndex;
}
$this->fixWhiteSpaceAroundHeader($tokens, $headerNewIndex);
}