/** * {@inheritdoc} */ public function fix(\SplFileInfo $file, Tokens $tokens) { // ignore non-monolithic files if (!$tokens->isMonolithicPhp()) { return; } // ignore files with short open tag if (!$tokens[0]->isGivenKind(T_OPEN_TAG)) { return; } $newlineFound = false; foreach ($tokens as $token) { if ($token->isWhitespace("\n")) { $newlineFound = true; break; } } // ignore one-line files if (!$newlineFound) { return; } $token = $tokens[0]; if (false === strpos($token->getContent(), "\n")) { $token->setContent(rtrim($token->getContent()) . "\n"); } if (!$tokens[1]->isWhitespace("\n")) { $tokens->insertAt(1, new Token(array(T_WHITESPACE, "\n"))); } }
/** * {@inheritdoc} */ public function fix(\SplFileInfo $file, Tokens $tokens) { if (!$tokens->isMonolithicPhp()) { return; } $oldHeaderIndex = $this->findHeaderCommentIndex($tokens); $newHeaderIndex = $this->findHeaderCommentInsertionIndex($tokens); if ($oldHeaderIndex === $newHeaderIndex && $this->headerComment === $tokens[$oldHeaderIndex]->getContent()) { return; } $this->replaceHeaderComment($tokens, $oldHeaderIndex); }
/** * {@inheritdoc} */ public function fix(\SplFileInfo $file, Tokens $tokens) { if (!$tokens->isMonolithicPhp()) { return; } $closeTags = $tokens->findGivenKind(T_CLOSE_TAG); if (empty($closeTags)) { return; } list($index, $token) = each($closeTags); $tokens->removeLeadingWhitespace($index); $token->clear(); $prevIndex = $tokens->getPrevNonWhitespace($index); $prevToken = $tokens[$prevIndex]; if (!$prevToken->equalsAny(array(';', '}'))) { $tokens->insertAt($prevIndex + 1, new Token(';')); } }