コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isGivenKind(array(T_CONST, T_FUNCTION))) {
         return;
     }
     $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
     if ($prevToken->isGivenKind(T_USE)) {
         $token->override(array($token->isGivenKind(T_FUNCTION) ? CT_FUNCTION_IMPORT : CT_CONST_IMPORT, $token->getContent()));
     }
 }
コード例 #2
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()));
         }
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isGivenKind(T_ARRAY)) {
         return;
     }
     $nextIndex = $tokens->getNextMeaningfulToken($index);
     $nextToken = $tokens[$nextIndex];
     if (!$nextToken->equals('(')) {
         $token->override(array(CT_ARRAY_TYPEHINT, $token->getContent()));
     }
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isGivenKind(T_NAMESPACE)) {
         return;
     }
     $nextIndex = $tokens->getNextMeaningfulToken($index);
     $nextToken = $tokens[$nextIndex];
     if ($nextToken->isGivenKind(T_NS_SEPARATOR)) {
         $token->override(array(CT::T_NAMESPACE_OPERATOR, $token->getContent()));
     }
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isGivenKind(T_CLASS)) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $tokens[$prevIndex];
     if ($prevToken->isGivenKind(T_DOUBLE_COLON)) {
         $token->override(array(CT_CLASS_CONSTANT, $token->getContent()));
     }
 }
コード例 #6
0
 private function fixByToken(Token $token, $index)
 {
     foreach ($this->tokenKindCallbackMap as $kind => $callback) {
         if (!$token->isGivenKind($kind)) {
             continue;
         }
         $this->{$callback}($index);
         return;
     }
     foreach ($this->tokenEqualsMap as $equals => $callback) {
         if (!$token->equals($equals)) {
             continue;
         }
         $this->{$callback}($index);
     }
 }
コード例 #7
0
 private function transformIntoDynamicPropBraces(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isGivenKind(T_OBJECT_OPERATOR)) {
         return;
     }
     if (!$tokens[$index + 1]->equals('{')) {
         return;
     }
     $openIndex = $index + 1;
     $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openIndex);
     $tokens[$openIndex]->override(array(CT_DYNAMIC_PROP_BRACE_OPEN, '{'));
     $tokens[$closeIndex]->override(array(CT_DYNAMIC_PROP_BRACE_CLOSE, '}'));
 }
コード例 #8
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);
 }
コード例 #9
0
 private function fixByToken(Token $token, $index)
 {
     foreach ($this->tokenCallbackMap as $kind => $callback) {
         if (!$token->isGivenKind($kind)) {
             continue;
         }
         $callback = $this->tokenCallbackMap[$kind];
         $this->{$callback}($index);
         return;
     }
 }