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


PHP Tokens::overrideAt方法代码示例

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


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

示例1: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $index => $token) {
         if ($token->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN)) {
             $tokens->overrideAt($index, new Token('['));
         } elseif ($token->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE)) {
             $tokens->overrideAt($index, new Token(']'));
         }
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:13,代码来源:NormalizeIndexBraceFixer.php

示例2: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
         $token = $tokens[$index];
         if (!$token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) {
             continue;
         }
         $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index);
         $tokens->overrideAt($index, '(');
         $tokens->overrideAt($closeIndex, ')');
         $tokens->insertAt($index, new Token(array(T_ARRAY, 'array')));
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:16,代码来源:LongArraySyntaxFixer.php

示例3: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $index => $token) {
         if (!$token->isGivenKind(T_ARRAY)) {
             continue;
         }
         $openIndex = $tokens->getNextTokenOfKind($index, array('('));
         $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
         $token->clear();
         $tokens->overrideAt($openIndex, array(CT_ARRAY_SQUARE_BRACE_OPEN, '['));
         $tokens->overrideAt($closeIndex, array(CT_ARRAY_SQUARE_BRACE_CLOSE, ']'));
     }
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:16,代码来源:ShortArraySyntaxFixer.php

示例4: 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;
         }
         $ifTokenIndex = $tokens->getNextMeaningfulToken($index);
         $beforeIfTokenIndex = $tokens->getPrevNonWhitespace($ifTokenIndex);
         // if next meaning token is not T_IF - continue searching, this is not the case for fixing
         if (!$tokens[$ifTokenIndex]->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
         $tokens[$ifTokenIndex]->clear();
         // 4. clear extra whitespace after T_IF in T_COMMENT,T_WHITESPACE?,T_IF,T_WHITESPACE sequence
         if ($tokens[$beforeIfTokenIndex]->isComment() && $tokens[$ifTokenIndex + 1]->isWhitespace()) {
             $tokens[$ifTokenIndex + 1]->clear();
         }
     }
 }
开发者ID:friendsofphp,项目名称:php-cs-fixer,代码行数:30,代码来源:ElseifFixer.php

示例5: 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;
         }
         $ifTokenIndex = $tokens->getNextMeaningfulToken($index);
         $beforeIfTokenIndex = $tokens->getPrevNonWhitespace($ifTokenIndex);
         // if next meaning token is not T_IF - continue searching, this is not the case for fixing
         if (!$tokens[$ifTokenIndex]->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
         $tokens[$ifTokenIndex]->clear();
         // 4. clear extra whitespace after T_IF in T_COMMENT,T_WHITESPACE?,T_IF,T_WHITESPACE sequence
         if ($tokens[$beforeIfTokenIndex]->isComment() && $tokens[$ifTokenIndex + 1]->isWhitespace()) {
             $tokens[$ifTokenIndex + 1]->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:thekabal,项目名称:tki,代码行数:37,代码来源:ElseifFixer.php

示例6: 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:cryode,项目名称:PHP-CS-Fixer,代码行数:28,代码来源:EchoToPrintFixer.php

示例7: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $index => $token) {
         if (!$token->isGivenKind(T_ECHO)) {
             continue;
         }
         /*
          * HHVM parses '<?=' as T_ECHO instead of T_OPEN_TAG_WITH_ECHO
          *
          * @see https://github.com/facebook/hhvm/issues/4809
          * @see https://github.com/facebook/hhvm/issues/7161
          */
         if (defined('HHVM_VERSION') && 0 === strpos($token->getContent(), '<?=')) {
             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:GrahamForks,项目名称:PHP-CS-Fixer,代码行数:37,代码来源:EchoToPrintFixer.php

示例8: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     static $controlStructures = array(T_FOREACH, T_IF, T_SWITCH, T_WHILE, T_FOR);
     foreach ($tokens as $index => $token) {
         if (!$token->isGivenKind(T_DOC_COMMENT)) {
             continue;
         }
         $nextIndex = $tokens->getNextMeaningfulToken($index);
         $nextToken = null !== $nextIndex ? $tokens[$nextIndex] : null;
         if (null === $nextToken || $nextToken->equals('}')) {
             $tokens->overrideAt($index, array(T_COMMENT, '/*' . ltrim($token->getContent(), '/*')));
             continue;
         }
         if ($this->isStructuralElement($nextToken)) {
             continue;
         }
         if ($nextToken->isGivenKind($controlStructures) && $this->isValidControl($tokens, $token, $nextIndex)) {
             continue;
         }
         if ($nextToken->isGivenKind(T_VARIABLE) && $this->isValidVariable($tokens, $token, $nextIndex)) {
             continue;
         }
         if ($nextToken->isGivenKind(T_LIST) && $this->isValidList($tokens, $token, $nextIndex)) {
             continue;
         }
         // First docblock after open tag can be file-level docblock, so its left as is.
         $prevIndex = $tokens->getPrevMeaningfulToken($index);
         if ($tokens[$prevIndex]->isGivenKind(array(T_OPEN_TAG, T_NAMESPACE))) {
             continue;
         }
         $tokens->overrideAt($index, array(T_COMMENT, '/*' . ltrim($token->getContent(), '/*')));
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:36,代码来源:PhpdocToCommentFixer.php

示例9: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     static $map = array(T_IS_EQUAL => array('id' => T_IS_IDENTICAL, 'content' => '==='), T_IS_NOT_EQUAL => array('id' => T_IS_NOT_IDENTICAL, 'content' => '!=='));
     foreach ($tokens as $index => $token) {
         $tokenId = $token->getId();
         if (isset($map[$tokenId])) {
             $tokens->overrideAt($index, array($map[$tokenId]['id'], $map[$tokenId]['content']));
         }
     }
 }
开发者ID:cryode,项目名称:PHP-CS-Fixer,代码行数:13,代码来源:StrictFixer.php

示例10: fixClass

 /**
  * @param Tokens $tokens
  * @param int    $classIndex
  * @param int    $classOpenIndex
  * @param int    $classCloseIndex
  */
 private function fixClass(Tokens $tokens, $classIndex, $classOpenIndex, $classCloseIndex)
 {
     for ($index = $classOpenIndex + 1; $index < $classCloseIndex; ++$index) {
         if ($tokens[$index]->equals('{')) {
             $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
             continue;
         }
         if (!$tokens[$index]->isGivenKind(T_PROTECTED)) {
             continue;
         }
         $tokens->overrideAt($index, array(T_PRIVATE, 'private'));
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:19,代码来源:ProtectedToPrivateFixer.php

示例11: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $index => $token) {
         if (!$token->isGivenKind(T_PRINT)) {
             continue;
         }
         $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
         if (!$prevToken->equalsAny(array(';', '{', '}', array(T_OPEN_TAG)))) {
             continue;
         }
         $tokens->overrideAt($index, array(T_ECHO, 'echo'));
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:16,代码来源:PrintToEchoFixer.php

示例12: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     /** @var Token $token */
     foreach ($tokens as $index => $token) {
         if ($token->isGivenKind(T_DOC_COMMENT)) {
             $token->setContent($this->fixTokenContent($token->getContent()));
             continue;
         }
         if (!$token->isGivenKind(T_COMMENT)) {
             continue;
         }
         $content = $token->getContent();
         $fixedContent = $this->fixTokenContent($content);
         if ($content !== $fixedContent) {
             $tokens->overrideAt($index, array(T_DOC_COMMENT, $fixedContent));
         }
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:21,代码来源:PhpdocSingleLineVarSpacingFixer.php

示例13: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $index => $token) {
         if (!$token->isGivenKind(array(T_CASE, T_DEFAULT))) {
             continue;
         }
         $ternariesCount = 0;
         for ($colonIndex = $index + 1;; ++$colonIndex) {
             // We have to skip ternary case for colons.
             if ($tokens[$colonIndex]->equals('?')) {
                 ++$ternariesCount;
             }
             if ($tokens[$colonIndex]->equalsAny(array(':', ';'))) {
                 if (0 === $ternariesCount) {
                     break;
                 }
                 --$ternariesCount;
             }
         }
         if ($tokens[$colonIndex]->equals(';')) {
             $tokens->overrideAt($colonIndex, ':');
         }
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:27,代码来源:SwitchCaseSemicolonToColonFixer.php

示例14: removeUseDeclaration

 private function removeUseDeclaration(Tokens $tokens, array $useDeclaration)
 {
     for ($index = $useDeclaration['end'] - 1; $index >= $useDeclaration['start']; --$index) {
         $tokens->clearTokenAndMergeSurroundingWhitespace($index);
     }
     if ($tokens[$useDeclaration['end']]->equals(';')) {
         $tokens[$useDeclaration['end']]->clear();
     }
     $prevToken = $tokens[$useDeclaration['start'] - 1];
     if ($prevToken->isWhitespace()) {
         $prevToken->setContent(rtrim($prevToken->getContent(), " \t"));
     }
     if (!isset($tokens[$useDeclaration['end'] + 1])) {
         return;
     }
     $nextIndex = $useDeclaration['end'] + 1;
     $nextToken = $tokens[$nextIndex];
     if ($nextToken->isWhitespace()) {
         $content = ltrim($nextToken->getContent(), " \t");
         $content = preg_replace("#^\r\n|^\n#", '', $content, 1);
         $nextToken->setContent($content);
     }
     if ($prevToken->isWhitespace() && $nextToken->isWhitespace()) {
         $tokens->overrideAt($nextIndex, array(T_WHITESPACE, $prevToken->getContent() . $nextToken->getContent()));
         $prevToken->clear();
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:27,代码来源:NoUnusedImportsFixer.php

示例15: fixMultipleUse

 private function fixMultipleUse(Tokens $tokens, $index, $endIndex)
 {
     $ending = $this->whitespacesConfig->getLineEnding();
     for ($i = $endIndex - 1; $i > $index; --$i) {
         if (!$tokens[$i]->equals(',')) {
             continue;
         }
         $tokens->overrideAt($i, new Token(';'));
         $i = $tokens->getNextMeaningfulToken($i);
         $tokens->insertAt($i, new Token(array(T_USE, 'use')));
         $tokens->insertAt($i + 1, new Token(array(T_WHITESPACE, ' ')));
         $indent = $this->detectIndent($tokens, $index);
         if ($tokens[$i - 1]->isWhitespace()) {
             $tokens[$i - 1]->setContent($ending . $indent);
             continue;
         }
         if (false === strpos($tokens[$i - 1]->getContent(), "\n")) {
             $tokens->insertAt($i, new Token(array(T_WHITESPACE, $ending . $indent)));
         }
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:21,代码来源:SingleImportPerStatementFixer.php


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