當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。