/** * {@inheritdoc} */ public function process(Tokens $tokens, Token $token, $index) { $prevTokenIndex = $tokens->getPrevMeaningfulToken($index); $prevToken = $prevTokenIndex === null ? null : $tokens[$prevTokenIndex]; // Skip whole class braces content. // That way we can skip whole tokens in class declaration, therefore skip `T_USE` for traits. if ($token->isClassy() && !$prevToken->isGivenKind(T_DOUBLE_COLON)) { $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())); } } return; } if ($token->isGivenKind(T_USE) && $this->isUseForLambda($tokens, $index)) { $token->override(array(CT_USE_LAMBDA, $token->getContent())); } }
private function isStructuralElement(Token $token) { static $skip = array( T_PRIVATE, T_PROTECTED, T_PUBLIC, 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); }