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


PHP Tokens::clearRange方法代码示例

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


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

示例1: fixAssertSame

 private function fixAssertSame(Tokens $tokens, $index)
 {
     static $map = array('false' => 'assertFalse', 'null' => 'assertNull', 'true' => 'assertTrue');
     $sequence = $tokens->findSequence(array(array(T_VARIABLE, '$this'), array(T_OBJECT_OPERATOR, '->'), array(T_STRING, 'assertSame'), '('), $index);
     if (null === $sequence) {
         return;
     }
     $sequenceIndexes = array_keys($sequence);
     $sequenceIndexes[4] = $tokens->getNextMeaningfulToken($sequenceIndexes[3]);
     $firstParameterToken = $tokens[$sequenceIndexes[4]];
     if (!$firstParameterToken->isNativeConstant()) {
         return;
     }
     $sequenceIndexes[5] = $tokens->getNextNonWhitespace($sequenceIndexes[4]);
     $tokens[$sequenceIndexes[2]]->setContent($map[$firstParameterToken->getContent()]);
     $tokens->clearRange($sequenceIndexes[4], $tokens->getNextNonWhitespace($sequenceIndexes[5]) - 1);
     return $sequenceIndexes[5];
 }
开发者ID:nazimodi,项目名称:PHP-CS-Fixer,代码行数:18,代码来源:PhpUnitConstructFixer.php

示例2: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     for ($index = $tokens->count() - 1; $index >= 0; --$index) {
         $token = $tokens[$index];
         if (!$token->isGivenKind(T_LIST)) {
             continue;
         }
         $openIndex = $tokens->getNextMeaningfulToken($index);
         $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
         $markIndex = null;
         $prevIndex = $tokens->getPrevNonWhitespace($closeIndex);
         while ($tokens[$prevIndex]->equals(',')) {
             $markIndex = $prevIndex;
             $prevIndex = $tokens->getPrevNonWhitespace($prevIndex);
         }
         if (null !== $markIndex) {
             $tokens->clearRange($tokens->getPrevNonWhitespace($markIndex) + 1, $closeIndex - 1);
         }
     }
 }
开发者ID:skillberto,项目名称:PHP-CS-Fixer,代码行数:23,代码来源:ListCommasFixer.php

示例3: fixAssert

 private function fixAssert(array $map, Tokens $tokens, $index, $method)
 {
     $sequence = $tokens->findSequence(array(array(T_VARIABLE, '$this'), array(T_OBJECT_OPERATOR, '->'), array(T_STRING, $method), '('), $index);
     if (null === $sequence) {
         return;
     }
     $sequenceIndexes = array_keys($sequence);
     $sequenceIndexes[4] = $tokens->getNextMeaningfulToken($sequenceIndexes[3]);
     $firstParameterToken = $tokens[$sequenceIndexes[4]];
     if (!$firstParameterToken->isNativeConstant()) {
         return;
     }
     $sequenceIndexes[5] = $tokens->getNextMeaningfulToken($sequenceIndexes[4]);
     if (!$tokens[$sequenceIndexes[5]]->equals(',')) {
         return;
     }
     $tokens[$sequenceIndexes[2]]->setContent($map[$firstParameterToken->getContent()]);
     $tokens->clearRange($sequenceIndexes[4], $tokens->getNextNonWhitespace($sequenceIndexes[5]) - 1);
     return $sequenceIndexes[5];
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:20,代码来源:PhpUnitConstructFixer.php

示例4: replaceHeaderComment

 /**
  * Replace the header comment at the given index.
  *
  * @param Tokens $tokens
  * @param int    $oldHeaderIndex
  */
 private function replaceHeaderComment(Tokens $tokens, $oldHeaderIndex)
 {
     if ('' === $this->headerComment) {
         if ($oldHeaderIndex) {
             $tokens->clearRange($oldHeaderIndex, $oldHeaderIndex + 1);
         }
         return;
     }
     $headCommentTokens = array(new Token(array(T_WHITESPACE, "\n")), new Token(array(T_COMMENT, $this->headerComment)), new Token(array(T_WHITESPACE, "\n\n")));
     $newHeaderIndex = null !== $oldHeaderIndex ? $oldHeaderIndex + 1 : $this->findHeaderCommentInsertionIndex($tokens) - 1;
     $tokens->overrideRange(1, $newHeaderIndex, $headCommentTokens);
 }
开发者ID:vuthao,项目名称:PHP-CS-Fixer,代码行数:18,代码来源:HeaderCommentFixer.php

示例5: replaceClassKeyword

 /**
  * @param Tokens $tokens
  * @param int    $classIndex
  */
 private function replaceClassKeyword(Tokens $tokens, $classIndex)
 {
     $classEndIndex = $classIndex - 2;
     $classBeginIndex = $classEndIndex;
     while ($tokens[--$classBeginIndex]->isGivenKind(array(T_NS_SEPARATOR, T_STRING))) {
     }
     ++$classBeginIndex;
     $classString = $tokens->generatePartialCode($classBeginIndex, $classEndIndex);
     $classImport = false;
     foreach ($this->imports as $alias => $import) {
         if ($classString === $alias) {
             $classImport = $import;
             break;
         }
         $classStringArray = explode('\\', $classString);
         $namespaceToTest = $classStringArray[0];
         if (0 === strcmp($namespaceToTest, substr($import, -strlen($namespaceToTest)))) {
             $classImport = $import;
             break;
         }
     }
     $tokens->clearRange($classBeginIndex, $classIndex);
     $tokens->insertAt($classBeginIndex, new Token(array(T_CONSTANT_ENCAPSED_STRING, "'" . $this->makeClassFQN($classImport, $classString) . "'")));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:28,代码来源:ClassKeywordRemoveFixer.php


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