isMonolithicPhp() public method

Checks that the code is pure PHP code, in a single code block, starting with an open tag.
public isMonolithicPhp ( ) : boolean
return boolean
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $lineEnding = $this->whitespacesConfig->getLineEnding();
     // ignore files with short open tag and ignore non-monolithic files
     if (!$tokens[0]->isGivenKind(T_OPEN_TAG) || !$tokens->isMonolithicPhp()) {
         return;
     }
     $newlineFound = false;
     /** @var Token $token */
     foreach ($tokens as $token) {
         if ($token->isWhitespace() && false !== strpos($token->getContent(), "\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()) . $lineEnding);
     }
     if (!$tokens[1]->isWhitespace() && false === strpos($tokens[1]->getContent(), "\n")) {
         $tokens->insertAt(1, new Token(array(T_WHITESPACE, $lineEnding)));
     }
 }
 /**
  * {@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);
 }
Esempio n. 3
0
 /**
  * {@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(';'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     // ignore files with short open tag and ignore non-monolithic files
     if (!$tokens[0]->isGivenKind(T_OPEN_TAG) || !$tokens->isMonolithicPhp()) {
         return;
     }
     $newlineFound = false;
     foreach ($tokens as $token) {
         if ($token->isWhitespace() && false !== strpos($token->getContent(), "\n")) {
             $newlineFound = true;
             break;
         }
     }
     // ignore one-line files
     if (!$newlineFound) {
         return;
     }
     $token = $tokens[0];
     $token->setContent(rtrim($token->getContent()) . "\n");
 }
 /**
  * {@inheritdoc}
  */
 public function isCandidate(Tokens $tokens)
 {
     return $tokens[0]->isGivenKind(T_OPEN_TAG) && $tokens->isMonolithicPhp();
 }