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


PHP Tokens::findGivenKind方法代碼示例

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


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

示例1: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_DOLLAR_OPEN_CURLY_BRACES) as $index => $token) {
         $nextIndex = $tokens->getNextTokenOfKind($index, array('}'));
         $tokens[$nextIndex]->override(array(CT_DOLLAR_CLOSE_CURLY_BRACES, '}', $tokens[$nextIndex]->getLine()));
     }
 }
開發者ID:Flesh192,項目名稱:magento,代碼行數:10,代碼來源:DollarCloseCurlyBraces.php

示例2: fix

 /**
  * Replace all `else if` (T_ELSE T_IF) with `elseif` (T_ELSEIF).
  *
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $index => $token) {
         if (!$token->isGivenKind(T_ELSE)) {
             continue;
         }
         $nextIndex = $tokens->getNextNonWhitespace($index);
         $nextToken = $tokens[$nextIndex];
         // if next meaning token is not T_IF - continue searching, this is not the case for fixing
         if (!$nextToken->isGivenKind(T_IF)) {
             continue;
         }
         // now we have T_ELSE following by T_IF so we could fix this
         // 1. clear whitespaces between T_ELSE and T_IF
         $tokens[$index + 1]->clear();
         // 2. change token from T_ELSE into T_ELSEIF
         $tokens->overrideAt($index, array(T_ELSEIF, 'elseif'));
         // 3. clear succeeding T_IF
         $nextToken->clear();
     }
     # handle `T_ELSE T_WHITESPACE T_IF` treated as single `T_ELSEIF` by HHVM
     # see https://github.com/facebook/hhvm/issues/4796
     if (defined('HHVM_VERSION')) {
         foreach ($tokens->findGivenKind(T_ELSEIF) as $token) {
             $token->setContent('elseif');
         }
     }
 }
開發者ID:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:33,代碼來源:ElseifFixer.php

示例3: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     /** @var $token \Symfony\CS\Tokenizer\Token */
     foreach ($tokens->findGivenKind(T_STRING) as $index => $token) {
         // skip expressions without parameters list
         $nextToken = $tokens[$tokens->getNextMeaningfulToken($index)];
         if (!$nextToken->equals('(')) {
             continue;
         }
         // skip expressions which are not function reference
         $prevTokenIndex = $tokens->getPrevMeaningfulToken($index);
         $prevToken = $tokens[$prevTokenIndex];
         if ($prevToken->isGivenKind(array(T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION))) {
             continue;
         }
         // handle function reference with namespaces
         if ($prevToken->isGivenKind(array(T_NS_SEPARATOR))) {
             $twicePrevTokenIndex = $tokens->getPrevMeaningfulToken($prevTokenIndex);
             $twicePrevToken = $tokens[$twicePrevTokenIndex];
             if ($twicePrevToken->isGivenKind(array(T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION, T_STRING, CT_NAMESPACE_OPERATOR))) {
                 continue;
             }
         }
         // check mapping hit
         $tokenContent = strtolower($token->getContent());
         if (!isset(self::$aliases[$tokenContent])) {
             continue;
         }
         $token->setContent(self::$aliases[$tokenContent]);
     }
 }
開發者ID:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:34,代碼來源:AliasFunctionsFixer.php

示例4: fixUseStatements

 private function fixUseStatements(Tokens $tokens)
 {
     $classIndexes = array_keys($tokens->findGivenKind(T_CLASS));
     if ($tokens->findSequence([[T_STRING, 'OptionsResolverInterface']], array_pop($classIndexes))) {
         return $this->addUseStatement($tokens, ['Symfony', 'Component', 'OptionsResolver', 'OptionsResolver']);
     }
     $this->renameUseStatements($tokens, ['Symfony', 'Component', 'OptionsResolver', 'OptionsResolverInterface'], 'OptionsResolver');
 }
開發者ID:akovalyov,項目名稱:Symfony-Upgrade-Fixer,代碼行數:8,代碼來源:FormConfigureOptionsFixer.php

示例5: 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

示例6: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_CLASS) as $index => $token) {
         $prevIndex = $tokens->getPrevMeaningfulToken($index);
         $prevToken = $tokens[$prevIndex];
         if ($prevToken->isGivenKind(T_DOUBLE_COLON)) {
             $token->override(array(CT_CLASS_CONSTANT, $token->getContent(), $token->getLine()));
         }
     }
 }
開發者ID:Flesh192,項目名稱:magento,代碼行數:13,代碼來源:ClassConstant.php

示例7: process

 public function process(Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_ARRAY) as $index => $token) {
         $nextIndex = $tokens->getNextMeaningfulToken($index);
         $nextToken = $tokens[$nextIndex];
         if (!$nextToken->equals('(')) {
             $token->override(array(CT_ARRAY_TYPEHINT, $token->getContent(), $token->getLine()));
         }
     }
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:10,代碼來源:ArrayTypehint.php

示例8: 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

示例9: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_OBJECT_OPERATOR) as $index => $token) {
         if (!$tokens[$index + 1]->equals('{')) {
             continue;
         }
         $openIndex = $index + 1;
         $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openIndex);
         $tokens[$openIndex]->override(array(CT_DYNAMIC_PROP_BRACE_OPEN, '{', $tokens[$openIndex]->getLine()));
         $tokens[$closeIndex]->override(array(CT_DYNAMIC_PROP_BRACE_CLOSE, '}', $tokens[$closeIndex]->getLine()));
     }
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:15,代碼來源:DynamicPropBrace.php

示例10: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $doc = new DocBlock($token->getContent());
         $annotations = $doc->getAnnotationsOfType(static::$search);
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $annotation->getTag()->setName(static::$replace);
         }
         $token->setContent($doc->getContent());
     }
 }
開發者ID:vuthao,項目名稱:PHP-CS-Fixer,代碼行數:17,代碼來源:AbstractPhpdocTagsFixer.php

示例11: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $doc = new DocBlock($token->getContent());
         $annotations = $doc->getAnnotationsOfType(static::$search);
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $line = $doc->getLine($annotation->getStart());
             $line->setContent(str_replace(static::$input, static::$output, $line->getContent()));
         }
         $token->setContent($doc->getContent());
     }
 }
開發者ID:jimlind,項目名稱:PHP-CS-Fixer,代碼行數:18,代碼來源:AbstractPhpdocTagsFixer.php

示例12: process

 public function process(Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_CURLY_OPEN) as $index => $token) {
         $level = 1;
         $nestIndex = $index;
         while (0 < $level) {
             ++$nestIndex;
             if ('{' === $tokens[$nestIndex]->getContent()) {
                 ++$level;
                 continue;
             }
             if ('}' === $tokens[$nestIndex]->getContent()) {
                 --$level;
             }
         }
         $tokens[$nestIndex]->override(array(CT_CURLY_CLOSE, '}', $tokens[$nestIndex]->getLine()));
     }
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:18,代碼來源:CurlyClose.php

示例13: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     if (!$tokens->isMonolithicPhp()) {
         return;
     }
     $closeTags = $tokens->findGivenKind(T_CLOSE_TAG);
     if (empty($closeTags)) {
         return;
     }
     list($index, $token) = each($closeTags);
     $tokens->removeLeadingWhitespace($index);
     $token->clear();
     $prevIndex = $tokens->getPrevNonWhitespace($index);
     $prevToken = $tokens[$prevIndex];
     if (!$prevToken->equalsAny(array(';', '}'))) {
         $tokens->insertAt($prevIndex + 1, new Token(';'));
     }
 }
開發者ID:vuthao,項目名稱:PHP-CS-Fixer,代碼行數:21,代碼來源:PhpClosingTagFixer.php

示例14: findIncludies

 private function findIncludies(Tokens $tokens)
 {
     static $includyTokenKinds = array(T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE);
     $includies = array();
     foreach ($tokens->findGivenKind($includyTokenKinds) as $includyTokens) {
         foreach ($includyTokens as $index => $token) {
             $includy = array('begin' => $index, 'braces' => null, 'end' => $tokens->getNextTokenOfKind($index, array(';')));
             $nextTokenIndex = $tokens->getNextMeaningfulToken($index);
             $nextToken = $tokens[$nextTokenIndex];
             if ($nextToken->equals('(')) {
                 $braceCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextTokenIndex);
                 if ($tokens[$tokens->getNextMeaningfulToken($braceCloseIndex)]->equals(';')) {
                     $includy['braces'] = array('open' => $nextTokenIndex, 'close' => $braceCloseIndex);
                 }
             }
             $includies[] = $includy;
         }
     }
     return $includies;
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:20,代碼來源:IncludeFixer.php

示例15: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $foundNamespace = $tokens->findGivenKind(T_NAMESPACE);
     if (empty($foundNamespace)) {
         return;
     }
     $tokensAnalyzer = new TokensAnalyzer($tokens);
     $firstNamespaceIdx = key($foundNamespace);
     $usesIdxs = $tokensAnalyzer->getImportUseIndexes();
     foreach ($usesIdxs as $idx) {
         if ($idx < $firstNamespaceIdx) {
             continue;
         }
         $nextTokenIdx = $tokens->getNextNonWhitespace($idx);
         $nextToken = $tokens[$nextTokenIdx];
         if ($nextToken->isGivenKind(T_NS_SEPARATOR)) {
             $nextToken->clear();
         }
     }
 }
開發者ID:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:23,代碼來源:RemoveLeadingSlashUseFixer.php


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