當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Token::override方法代碼示例

本文整理匯總了PHP中PhpCsFixer\Tokenizer\Token::override方法的典型用法代碼示例。如果您正苦於以下問題:PHP Token::override方法的具體用法?PHP Token::override怎麽用?PHP Token::override使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PhpCsFixer\Tokenizer\Token的用法示例。


在下文中一共展示了Token::override方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: process

 /**
  * {@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()));
         }
     }
 }
開發者ID:cryode,項目名稱:PHP-CS-Fixer,代碼行數:32,代碼來源:UseTransformer.php

示例2: transformIntoDestructuringSquareBrace

 private function transformIntoDestructuringSquareBrace(Tokens $tokens, Token $token, $index)
 {
     if (null === $this->cacheOfArraySquareBraceCloseIndex || !$tokens[$tokens->getNextMeaningfulToken($this->cacheOfArraySquareBraceCloseIndex)]->equals('=')) {
         return;
     }
     $token->override(array(CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN, '['));
     $tokens[$this->cacheOfArraySquareBraceCloseIndex]->override(array(CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE, ']'));
 }
開發者ID:friendsofphp,項目名稱:php-cs-fixer,代碼行數:8,代碼來源:SquareBraceTransformer.php

示例3: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$this->isShortArray($tokens, $index)) {
         return;
     }
     $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index);
     $token->override(array(CT_ARRAY_SQUARE_BRACE_OPEN, '['));
     $tokens[$endIndex]->override(array(CT_ARRAY_SQUARE_BRACE_CLOSE, ']'));
 }
開發者ID:infinitely-young,項目名稱:PHP-CS-Fixer,代碼行數:12,代碼來源:ArraySquareBraceTransformer.php

示例4: process

 /**
  * {@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()));
     }
 }
開發者ID:infinitely-young,項目名稱:PHP-CS-Fixer,代碼行數:13,代碼來源:ImportTransformer.php

示例5: process

 /**
  * {@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()));
     }
 }
開發者ID:cryode,項目名稱:PHP-CS-Fixer,代碼行數:14,代碼來源:ArrayTypehintTransformer.php

示例6: process

 /**
  * {@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()));
     }
 }
開發者ID:fabpot,項目名稱:php-cs-fixer,代碼行數:14,代碼來源:NamespaceOperatorTransformer.php

示例7: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->equals('?')) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $tokens[$prevIndex];
     if ($prevToken->equalsAny(array('(', ',', array(CT::T_TYPE_COLON)))) {
         $token->override(array(CT::T_NULLABLE_TYPE, '?'));
     }
 }
開發者ID:fabpot,項目名稱:php-cs-fixer,代碼行數:14,代碼來源:NullableTypeTransformer.php

示例8: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->equalsAny(array(array(T_CLASS, 'class'), array(T_STRING, 'class')), false)) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $tokens[$prevIndex];
     if ($prevToken->isGivenKind(T_DOUBLE_COLON)) {
         $token->override(array(CT::T_CLASS_CONSTANT, $token->getContent()));
     }
 }
開發者ID:fabpot,項目名稱:php-cs-fixer,代碼行數:14,代碼來源:ClassConstantTransformer.php

示例9: process

 /**
  * {@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()));
     }
 }
開發者ID:infinitely-young,項目名稱:PHP-CS-Fixer,代碼行數:14,代碼來源:ClassConstantTransformer.php

示例10: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->equals('|')) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $tokens[$prevIndex];
     if (!$prevToken->isGivenKind(T_STRING)) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
     $prevToken = $tokens[$prevIndex];
     if (!$prevToken->equalsAny(array('(', array(CT::T_TYPE_ALTERNATION)))) {
         return;
     }
     $token->override(array(CT::T_TYPE_ALTERNATION, '|'));
 }
開發者ID:fabpot,項目名稱:php-cs-fixer,代碼行數:20,代碼來源:TypeAlternationTransformer.php

示例11: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->equals(':')) {
         return;
     }
     $endIndex = $tokens->getPrevMeaningfulToken($index);
     if (!$tokens[$endIndex]->equals(')')) {
         return;
     }
     $startIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $endIndex, false);
     $prevIndex = $tokens->getPrevMeaningfulToken($startIndex);
     $prevToken = $tokens[$prevIndex];
     // if this could be a function name we need to take one more step
     if ($prevToken->isGivenKind(T_STRING)) {
         $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
         $prevToken = $tokens[$prevIndex];
     }
     if ($prevToken->isGivenKind(array(T_FUNCTION, CT::T_RETURN_REF, CT::T_USE_LAMBDA))) {
         $token->override(array(CT::T_TYPE_COLON, ':'));
     }
 }
開發者ID:fabpot,項目名稱:php-cs-fixer,代碼行數:24,代碼來源:TypeColonTransformer.php

示例12: transformIntoGroupUseBraces

 private function transformIntoGroupUseBraces(Tokens $tokens, Token $token, $index)
 {
     if (!$token->equals('{')) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     if (!$tokens[$prevIndex]->isGivenKind(T_NS_SEPARATOR)) {
         return;
     }
     $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
     $closeToken = $tokens[$closeIndex];
     $token->override(array(CT::T_GROUP_IMPORT_BRACE_OPEN, '{'));
     $closeToken->override(array(CT::T_GROUP_IMPORT_BRACE_CLOSE, '}'));
 }
開發者ID:fabpot,項目名稱:php-cs-fixer,代碼行數:14,代碼來源:CurlyBraceTransformer.php

示例13: testIsEmpty

 public function testIsEmpty()
 {
     $braceToken = $this->getBraceToken();
     $this->assertFalse($braceToken->isEmpty());
     $braceToken->setContent('');
     $this->assertTrue($braceToken->isEmpty());
     $whitespaceToken = new Token(array(T_WHITESPACE, ' '));
     $this->assertFalse($whitespaceToken->isEmpty());
     $whitespaceToken->setContent('');
     $this->assertTrue($whitespaceToken->isEmpty());
     $whitespaceToken->override(array(null, ''));
     $this->assertTrue($whitespaceToken->isEmpty());
     $whitespaceToken = new Token(array(T_WHITESPACE, ' '));
     $whitespaceToken->clear();
     $this->assertTrue($whitespaceToken->isEmpty());
 }
開發者ID:cryode,項目名稱:PHP-CS-Fixer,代碼行數:16,代碼來源:TokenTest.php

示例14: transformIntoCurlyIndexBraces

 private function transformIntoCurlyIndexBraces(Tokens $tokens, Token $token, $index)
 {
     if (!$token->equals('{')) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     if (!$tokens[$prevIndex]->equalsAny(array(array(T_STRING), array(T_VARIABLE), array(CT_ARRAY_INDEX_CURLY_BRACE_CLOSE), array(CT_ARRAY_SQUARE_BRACE_CLOSE), ']', ')'))) {
         return;
     }
     if ($tokens[$prevIndex]->isGivenKind(T_STRING) && !$tokens[$tokens->getPrevMeaningfulToken($prevIndex)]->isGivenKind(T_OBJECT_OPERATOR)) {
         return;
     }
     if ($tokens[$prevIndex]->equals(')') && !$tokens[$tokens->getPrevMeaningfulToken($tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $prevIndex, false))]->isGivenKind(T_ARRAY)) {
         return;
     }
     $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
     $closeToken = $tokens[$closeIndex];
     $token->override(array(CT_ARRAY_INDEX_CURLY_BRACE_OPEN, '{'));
     $closeToken->override(array(CT_ARRAY_INDEX_CURLY_BRACE_CLOSE, '}'));
 }
開發者ID:phansys,項目名稱:PHP-CS-Fixer,代碼行數:20,代碼來源:CurlyBraceTransformer.php

示例15: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if ($token->equals('&') && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind(T_FUNCTION)) {
         $token->override(array(CT_RETURN_REF, '&'));
     }
 }
開發者ID:GrahamForks,項目名稱:PHP-CS-Fixer,代碼行數:9,代碼來源:ReturnRefTransformer.php


注:本文中的PhpCsFixer\Tokenizer\Token::override方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。