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


PHP Tokens::detectBlockType方法代码示例

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


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

示例1: findStart

 private function findStart(Tokens $tokens, $index)
 {
     do {
         $index = $tokens->getPrevMeaningfulToken($index);
         $token = $tokens[$index];
         $blockType = $tokens->detectBlockType($token);
         if (null !== $blockType && !$blockType['isStart']) {
             $index = $tokens->findBlockEnd($blockType['type'], $index, false);
             $token = $tokens[$index];
         }
     } while (!$token->equalsAny(array('$', array(T_VARIABLE))));
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $tokens[$prevIndex];
     if ($prevToken->equals('$')) {
         $index = $prevIndex;
         $prevIndex = $tokens->getPrevMeaningfulToken($index);
         $prevToken = $tokens[$prevIndex];
     }
     if ($prevToken->isGivenKind(T_OBJECT_OPERATOR)) {
         return $this->findStart($tokens, $prevIndex);
     }
     if ($prevToken->isGivenKind(T_PAAMAYIM_NEKUDOTAYIM)) {
         $prevPrevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
         if (!$tokens[$prevPrevIndex]->isGivenKind(T_STRING)) {
             return $this->findStart($tokens, $prevIndex);
         }
         $index = $tokens->getTokenNotOfKindSibling($prevIndex, -1, array(array(T_NS_SEPARATOR), array(T_STRING)));
         $index = $tokens->getNextMeaningfulToken($index);
     }
     return $index;
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:31,代码来源:PreIncrementFixer.php

示例2: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $index => $token) {
         if (!$token->isGivenKind(T_ECHO)) {
             continue;
         }
         $nextTokenIndex = $tokens->getNextMeaningfulToken($index);
         $endTokenIndex = $tokens->getNextTokenOfKind($index, array(';', array(T_CLOSE_TAG)));
         $canBeConverted = true;
         for ($i = $nextTokenIndex; $i < $endTokenIndex; ++$i) {
             if ($tokens[$i]->equalsAny(array('(', array(CT_ARRAY_SQUARE_BRACE_OPEN)))) {
                 $blockType = $tokens->detectBlockType($tokens[$i]);
                 $i = $tokens->findBlockEnd($blockType['type'], $i);
             }
             if ($tokens[$i]->equals(',')) {
                 $canBeConverted = false;
                 break;
             }
         }
         if (false === $canBeConverted) {
             continue;
         }
         $tokens->overrideAt($index, array(T_PRINT, 'print'));
     }
 }
开发者ID:skillberto,项目名称:PHP-CS-Fixer,代码行数:28,代码来源:EchoToPrintFixer.php

示例3: injectAlignmentPlaceholders

 /**
  * Inject into the text placeholders of candidates of vertical alignment.
  *
  * @param Tokens $tokens
  * @param int    $startAt
  * @param int    $endAt
  *
  * @return array($code, $context_counter)
  */
 private function injectAlignmentPlaceholders(Tokens $tokens, $startAt, $endAt)
 {
     for ($index = $startAt; $index < $endAt; ++$index) {
         $token = $tokens[$index];
         if ($token->isGivenKind(array(T_FOREACH, T_FOR, T_WHILE, T_IF, T_SWITCH))) {
             $index = $tokens->getNextMeaningfulToken($index);
             $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
             continue;
         }
         if ($token->isGivenKind(T_ARRAY)) {
             // don't use "$tokens->isArray()" here, short arrays are handled in the next case
             $from = $tokens->getNextMeaningfulToken($index);
             $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $from);
             $index = $until;
             $this->injectArrayAlignmentPlaceholders($tokens, $from, $until);
             continue;
         }
         if ($token->isGivenKind(CT_ARRAY_SQUARE_BRACE_OPEN)) {
             $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
             if ($prevToken->isGivenKind(array(T_STRING, T_VARIABLE))) {
                 continue;
             }
             $from = $index;
             $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $from);
             $index = $until;
             $this->injectArrayAlignmentPlaceholders($tokens, $from + 1, $until - 1);
             continue;
         }
         if ($token->isGivenKind(T_DOUBLE_ARROW)) {
             $tokenContent = sprintf(self::ALIGNABLE_PLACEHOLDER, $this->currentLevel) . $token->getContent();
             $nextToken = $tokens[$index + 1];
             if (!$nextToken->isWhitespace()) {
                 $tokenContent .= ' ';
             } elseif ($nextToken->isWhitespace(" \t")) {
                 $nextToken->setContent(' ');
             }
             $token->setContent($tokenContent);
             continue;
         }
         if ($token->equals(';')) {
             ++$this->deepestLevel;
             ++$this->currentLevel;
             continue;
         }
         if ($token->equals(',')) {
             for ($i = $index; $i < $endAt - 1; ++$i) {
                 if (false !== strpos($tokens[$i - 1]->getContent(), "\n")) {
                     break;
                 }
                 if ($tokens[$i + 1]->isGivenKind(array(T_ARRAY, CT_ARRAY_SQUARE_BRACE_OPEN))) {
                     $arrayStartIndex = $tokens[$i + 1]->isGivenKind(T_ARRAY) ? $tokens->getNextMeaningfulToken($i + 1) : $i + 1;
                     $blockType = Tokens::detectBlockType($tokens[$arrayStartIndex]);
                     $arrayEndIndex = $tokens->findBlockEnd($blockType['type'], $arrayStartIndex);
                     if ($tokens->isPartialCodeMultiline($arrayStartIndex, $arrayEndIndex)) {
                         break;
                     }
                 }
                 ++$index;
             }
         }
     }
 }
开发者ID:skillberto,项目名称:PHP-CS-Fixer,代码行数:71,代码来源:AlignDoubleArrowFixer.php


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