コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if ($token->isGivenKind(T_USE) && $this->isUseForLambda($tokens, $index)) {
         $token->override(array(CT_USE_LAMBDA, $token->getContent()));
     }
     if (!$token->isClassy()) {
         return;
     }
     $prevTokenIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $prevTokenIndex === null ? null : $tokens[$prevTokenIndex];
     if ($prevToken->isGivenKind(T_DOUBLE_COLON)) {
         return;
     }
     // Skip whole class braces content.
     // That way we can skip whole tokens in class declaration, therefore skip `T_USE` for traits.
     $index = $tokens->getNextTokenOfKind($index, array('{'));
     $innerLimit = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
     while ($index < $innerLimit) {
         $token = $tokens[++$index];
         if (!$token->isGivenKind(T_USE)) {
             continue;
         }
         if ($this->isUseForLambda($tokens, $index)) {
             $token->override(array(CT_USE_LAMBDA, $token->getContent()));
         } else {
             $token->override(array(CT_USE_TRAIT, $token->getContent()));
         }
     }
 }
コード例 #2
0
 /**
  * Check if token is a structural element.
  *
  * @see https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#3-definitions
  *
  * @param Token $token
  *
  * @return bool
  */
 private function isStructuralElement(Token $token)
 {
     static $skip = array(T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR, T_FUNCTION, T_ABSTRACT, T_CONST, T_NAMESPACE, T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE, T_FINAL, T_STATIC);
     return $token->isClassy() || $token->isGivenKind($skip);
 }