public function process(XHPASTNode $root)
 {
     $tokens = $root->getTokens();
     foreach ($tokens as $token) {
         if ($token->getTypeName() === 'T_OPEN_TAG_WITH_ECHO') {
             $this->raiseLintAtToken($token, pht('Avoid the PHP echo short form, "%s".', '<?='));
         }
     }
 }
 public function process(XHPASTNode $root)
 {
     $tokens = $root->getTokens();
     foreach ($tokens as $token) {
         if ($token->getTypeName() === 'T_OPEN_TAG') {
             if (trim($token->getValue()) === '<?') {
                 $this->raiseLintAtToken($token, pht('Use the full form of the PHP open tag, "%s".', '<?php'), "<?php\n");
             }
             break;
         }
     }
 }
 public function process(XHPASTNode $root)
 {
     $tokens = $root->getTokens();
     foreach ($tokens as $token) {
         switch ($token->getTypeName()) {
             case 'T_OPEN_TAG':
             case 'T_CLOSE_TAG':
             case 'T_WHITESPACE':
                 break;
             default:
                 return;
         }
     }
     $this->raiseLintAtPath(pht("Empty files usually don't serve any useful purpose."));
 }
 public function process(XHPASTNode $root)
 {
     $tokens = $root->getTokens();
     foreach ($tokens as $token) {
         if ($token->getTypeName() === 'T_OPEN_TAG') {
             break;
         } else {
             if ($token->getTypeName() === 'T_OPEN_TAG_WITH_ECHO') {
                 break;
             } else {
                 if (!preg_match('/^#!/', $token->getValue())) {
                     $this->raiseLintAtToken($token, pht('PHP files should start with `%s`, which may be preceded by ' . 'a `%s` line for scripts.', '<?php', '#!'));
                 }
                 break;
             }
         }
     }
 }
 public function process(XHPASTNode $root)
 {
     foreach ($root->getTokens() as $id => $token) {
         switch ($token->getTypeName()) {
             case 'T_IF':
             case 'T_ELSE':
             case 'T_FOR':
             case 'T_FOREACH':
             case 'T_WHILE':
             case 'T_DO':
             case 'T_SWITCH':
             case 'T_CATCH':
                 $after = $token->getNonsemanticTokensAfter();
                 if (empty($after)) {
                     $this->raiseLintAtToken($token, pht('Convention: put a space after control statements.'), $token->getValue() . ' ');
                 } else {
                     if (count($after) === 1) {
                         $space = head($after);
                         // If we have an else clause with braces, $space may not be
                         // a single white space. e.g.,
                         //
                         //   if ($x)
                         //     echo 'foo'
                         //   else          // <- $space is not " " but "\n  ".
                         //     echo 'bar'
                         //
                         // We just require it starts with either a whitespace or a newline.
                         if ($token->getTypeName() === 'T_ELSE' || $token->getTypeName() === 'T_DO') {
                             break;
                         }
                         if ($space->isAnyWhitespace() && $space->getValue() !== ' ') {
                             $this->raiseLintAtToken($space, pht('Convention: put a single space after control statements.'), ' ');
                         }
                     }
                 }
                 break;
         }
     }
 }
 private function findAtomDocblock(DivinerAtom $atom, XHPASTNode $node)
 {
     $token = $node->getDocblockToken();
     if ($token) {
         $atom->setDocblockRaw($token->getValue());
         return true;
     } else {
         $tokens = $node->getTokens();
         if ($tokens) {
             $prev = head($tokens);
             while ($prev = $prev->getPrevToken()) {
                 if ($prev->isAnyWhitespace()) {
                     continue;
                 }
                 break;
             }
             if ($prev && $prev->isComment()) {
                 $value = $prev->getValue();
                 $matches = null;
                 if (preg_match('/@(return|param|task|author)/', $value, $matches)) {
                     $atom->addWarning(pht('Atom "%s" is preceded by a comment containing `%s`, but ' . 'the comment is not a documentation comment. Documentation ' . 'comments must begin with `%s`, followed by a newline. Did ' . 'you mean to use a documentation comment? (As the comment is ' . 'not a documentation comment, it will be ignored.)', $atom->getName(), '@' . $matches[1], '/**'));
                 }
             }
         }
         $atom->setDocblockRaw('');
         return false;
     }
 }