当前位置: 首页>>代码示例>>PHP>>正文


PHP Tokens::getTokenNotOfKindSibling方法代码示例

本文整理汇总了PHP中Symfony\CS\Tokenizer\Tokens::getTokenNotOfKindSibling方法的典型用法代码示例。如果您正苦于以下问题:PHP Tokens::getTokenNotOfKindSibling方法的具体用法?PHP Tokens::getTokenNotOfKindSibling怎么用?PHP Tokens::getTokenNotOfKindSibling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\CS\Tokenizer\Tokens的用法示例。


在下文中一共展示了Tokens::getTokenNotOfKindSibling方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getNewOrder

 private function getNewOrder(array $uses, Tokens $tokens)
 {
     $uses = array_reverse($uses);
     $indexes = array();
     $originalIndexes = array();
     foreach ($uses as $index) {
         $endIndex = $tokens->getNextTokenOfKind($index, array(';'));
         $startIndex = $tokens->getTokenNotOfKindSibling($index + 1, 1, array(array(T_WHITESPACE)));
         $namespace = '';
         $index = $startIndex;
         while ($index <= $endIndex) {
             $token = $tokens[$index];
             /** @var Token $token */
             if ($token->equals(',') || $index === $endIndex) {
                 $indexes[$startIndex] = array($namespace, $startIndex, $index - 1);
                 $originalIndexes[] = $startIndex;
                 $namespace = '';
                 $nextPartIndex = $tokens->getTokenNotOfKindSibling($index, 1, array(array(','), array(T_WHITESPACE)));
                 $startIndex = $nextPartIndex;
                 $index = $nextPartIndex;
                 continue;
             }
             $namespace .= $token->getContent();
             ++$index;
         }
     }
     uasort($indexes, 'self::sortingCallBack');
     $i = -1;
     $usesOrder = array();
     // Loop trough the index but use original index order
     foreach ($indexes as $v) {
         $usesOrder[$originalIndexes[++$i]] = $v;
     }
     return $usesOrder;
 }
开发者ID:bgotink,项目名称:PHP-CS-Fixer,代码行数:35,代码来源:OrderedUseFixer.php

示例2: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_ARRAY) as $index => $token) {
         $nextIndex = $tokens->getTokenNotOfKindSibling($index, 1, array(array(T_WHITESPACE), array(T_COMMENT), array(T_DOC_COMMENT)));
         $nextToken = $tokens[$nextIndex];
         if (!$nextToken->equals('(')) {
             $token->override(array(CT_ARRAY_TYPEHINT, $token->getContent(), $token->getLine()));
         }
     }
 }
开发者ID:bgotink,项目名称:PHP-CS-Fixer,代码行数:13,代码来源:ArrayTypehint.php

示例3: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_CLASS) as $index => $token) {
         $prevIndex = $tokens->getTokenNotOfKindSibling($index, -1, array(array(T_WHITESPACE), array(T_COMMENT), array(T_DOC_COMMENT)));
         $prevToken = $tokens[$prevIndex];
         if ($prevToken->isGivenKind(T_DOUBLE_COLON)) {
             $token->override(array(CT_CLASS_CONSTANT, $token->getContent(), $token->getLine()));
         }
     }
 }
开发者ID:bgotink,项目名称:PHP-CS-Fixer,代码行数:13,代码来源:ClassConstant.php

示例4: fixArray

 private function fixArray(Tokens $tokens, $index)
 {
     if (!$tokens->isArrayMultiLine($index)) {
         return;
     }
     $startIndex = $index;
     if ($tokens[$startIndex]->isGivenKind(T_ARRAY)) {
         $startIndex = $tokens->getNextTokenOfKind($startIndex, array('('));
         $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
     } else {
         $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_SQUARE_BRACE, $startIndex);
     }
     $beforeEndIndex = $tokens->getTokenNotOfKindSibling($endIndex, -1, array(array(T_WHITESPACE), array(T_COMMENT), array(T_DOC_COMMENT)));
     $beforeEndToken = $tokens[$beforeEndIndex];
     // if there is some item between braces then add `,` after it
     if ($startIndex !== $beforeEndIndex && !$beforeEndToken->equalsAny(array(',', array(T_END_HEREDOC)))) {
         $tokens->insertAt($beforeEndIndex + 1, new Token(','));
     }
 }
开发者ID:bgotink,项目名称:PHP-CS-Fixer,代码行数:19,代码来源:MultilineArrayTrailingCommaFixer.php

示例5: fixArray

 private function fixArray(Tokens $tokens, $index)
 {
     if ($tokens->isArrayMultiLine($index)) {
         return;
     }
     $startIndex = $index;
     if ($tokens[$startIndex]->isGivenKind(T_ARRAY)) {
         $startIndex = $tokens->getNextTokenOfKind($startIndex, array('('));
         $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
     } else {
         $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_SQUARE_BRACE, $startIndex);
     }
     $beforeEndIndex = $tokens->getTokenNotOfKindSibling($endIndex, -1, array(array(T_WHITESPACE), array(T_COMMENT), array(T_DOC_COMMENT)));
     $beforeEndToken = $tokens[$beforeEndIndex];
     if ($beforeEndToken->equals(',')) {
         $tokens->removeTrailingWhitespace($beforeEndIndex);
         $beforeEndToken->clear();
     }
 }
开发者ID:bgotink,项目名称:PHP-CS-Fixer,代码行数:19,代码来源:SingleArrayNoTrailingCommaFixer.php

示例6: getNewOrder

 private function getNewOrder(array $uses, Tokens $tokens)
 {
     $uses = array_reverse($uses);
     $indexes = array();
     $originalIndexes = array();
     foreach ($uses as $index) {
         $startIndex = $tokens->getTokenNotOfKindSibling($index + 1, 1, array(array(T_WHITESPACE)));
         $endIndex = $tokens->getNextTokenOfKind($startIndex, array(';', array(T_CLOSE_TAG)));
         $previous = $tokens->getPrevMeaningfulToken($endIndex);
         $group = $tokens[$previous]->equals('}');
         if ($tokens[$startIndex]->isGivenKind(array(T_CONST))) {
             $type = self::IMPORT_TYPE_CONST;
         } elseif ($tokens[$startIndex]->isGivenKind(array(T_FUNCTION))) {
             $type = self::IMPORT_TYPE_FUNCTION;
         } else {
             $type = self::IMPORT_TYPE_CLASS;
         }
         $namespace = '';
         $index = $startIndex;
         while ($index <= $endIndex) {
             $token = $tokens[$index];
             if ($index === $endIndex || !$group && $token->equals(',')) {
                 $indexes[$startIndex] = array('namespace' => $namespace, 'startIndex' => $startIndex, 'endIndex' => $index - 1, 'importType' => $type);
                 $originalIndexes[] = $startIndex;
                 if ($index === $endIndex) {
                     break;
                 }
                 $namespace = '';
                 $nextPartIndex = $tokens->getTokenNotOfKindSibling($index, 1, array(array(','), array(T_WHITESPACE)));
                 $startIndex = $nextPartIndex;
                 $index = $nextPartIndex;
                 continue;
             }
             $namespace .= $token->getContent();
             ++$index;
         }
     }
     uasort($indexes, 'self::sortingCallBack');
     $index = -1;
     $usesOrder = array();
     // Loop trough the index but use original index order
     foreach ($indexes as $v) {
         $usesOrder[$originalIndexes[++$index]] = $v;
     }
     return $usesOrder;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:46,代码来源:OrderedUseFixer.php


注:本文中的Symfony\CS\Tokenizer\Tokens::getTokenNotOfKindSibling方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。