/**
  * Cleanup a whitespace token.
  *
  * @param Token $token
  */
 private function fixWhitespace(Token $token)
 {
     $content = $token->getContent();
     // if there is more than one new line in the whitespace, then we need to fix it
     if (substr_count($content, "\n") > 1) {
         // the final bit of the whitespace must be the next statement's indentation
         $lines = Utils::splitLines($content);
         $token->setContent("\n" . end($lines));
     }
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isComment()) {
         return;
     }
     $content = $token->getContent();
     $trimmedContent = rtrim($content);
     // nothing trimmed, nothing to do
     if ($content === $trimmedContent) {
         return;
     }
     $whitespaces = substr($content, strlen($trimmedContent));
     $token->setContent($trimmedContent);
     if (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) {
         $tokens[$index + 1]->setContent($whitespaces . $tokens[$index + 1]->getContent());
     } else {
         $tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, $whitespaces)));
     }
 }
コード例 #3
0
 /**
  * Transforms the heredoc start token to nowdoc notation.
  *
  * @param Token $token
  */
 private function convertToNowdoc(Token $token)
 {
     $token->setContent(preg_replace('/(?<=^<<<)"?(.*?)"?$/', '\'$1\'', $token->getContent()));
 }
コード例 #4
0
 /**
  * If given token is a single line whitespace then fix it to be a single space.
  *
  * @param Token $token
  */
 private function fixWhitespace(Token $token)
 {
     if ($token->isWhitespace(" \t")) {
         $token->setContent(' ');
     }
 }
 private function fixWhitespace(Token $token)
 {
     if ($token->isWhitespace() && !$token->isWhitespace(" \t")) {
         $token->setContent(rtrim($token->getContent()) . ' ');
     }
 }
コード例 #6
0
ファイル: TokenTest.php プロジェクト: cryode/PHP-CS-Fixer
 public function testIsEmpty()
 {
     $braceToken = $this->getBraceToken();
     $this->assertFalse($braceToken->isEmpty());
     $braceToken->setContent('');
     $this->assertTrue($braceToken->isEmpty());
     $whitespaceToken = new Token(array(T_WHITESPACE, ' '));
     $this->assertFalse($whitespaceToken->isEmpty());
     $whitespaceToken->setContent('');
     $this->assertTrue($whitespaceToken->isEmpty());
     $whitespaceToken->override(array(null, ''));
     $this->assertTrue($whitespaceToken->isEmpty());
     $whitespaceToken = new Token(array(T_WHITESPACE, ' '));
     $whitespaceToken->clear();
     $this->assertTrue($whitespaceToken->isEmpty());
 }