本文整理汇总了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];
}
示例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);
}
}
}
示例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];
}
示例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);
}
示例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) . "'")));
}