本文整理匯總了PHP中Symfony\CS\Tokenizer\Tokens::removeLeadingWhitespace方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tokens::removeLeadingWhitespace方法的具體用法?PHP Tokens::removeLeadingWhitespace怎麽用?PHP Tokens::removeLeadingWhitespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\CS\Tokenizer\Tokens
的用法示例。
在下文中一共展示了Tokens::removeLeadingWhitespace方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: clearIncludies
private function clearIncludies(Tokens $tokens, array $includies)
{
foreach (array_reverse($includies) as $includy) {
if ($includy['end']) {
$tokens->removeLeadingWhitespace($includy['end']);
}
$braces = $includy['braces'];
if ($braces) {
$nextToken = $tokens[$tokens->getNextMeaningfulToken($braces['close'])];
if ($nextToken->equals(';')) {
$tokens->removeLeadingWhitespace($braces['open']);
$tokens->removeTrailingWhitespace($braces['open']);
$tokens->removeLeadingWhitespace($braces['close']);
$tokens->removeTrailingWhitespace($braces['close']);
$tokens[$braces['open']] = new Token(array(T_WHITESPACE, ' '));
$tokens[$braces['close']]->clear();
}
}
$nextIndex = $includy['begin'] + 1;
$nextToken = $tokens[$nextIndex];
while ($nextToken->isEmpty()) {
$nextToken = $tokens[++$nextIndex];
}
if ($nextToken->isWhitespace()) {
$nextToken->setContent(' ');
} elseif ($braces) {
$tokens->insertAt($includy['begin'] + 1, new Token(array(T_WHITESPACE, ' ')));
}
}
}
示例2: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
for ($index = $tokens->count() - 1; $index >= 0; --$index) {
if ($tokensAnalyzer->isUnarySuccessorOperator($index)) {
$tokens->removeLeadingWhitespace($index);
continue;
}
if ($tokensAnalyzer->isUnaryPredecessorOperator($index)) {
$tokens->removeTrailingWhitespace($index);
continue;
}
}
}
示例3: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
foreach ($tokens as $index => $token) {
if (!$token->equals('.')) {
continue;
}
if (!$tokens[$tokens->getPrevNonWhitespace($index)]->isGivenKind(T_LNUMBER)) {
$tokens->removeLeadingWhitespace($index, " \t");
}
if (!$tokens[$tokens->getNextNonWhitespace($index)]->isGivenKind(T_LNUMBER)) {
$tokens->removeTrailingWhitespace($index, " \t");
}
}
}
示例4: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$limit = $tokens->count();
for ($index = 0; $index < $limit; ++$index) {
$token = $tokens[$index];
// skip T_FOR parenthesis to ignore duplicated `;` like `for ($i = 1; ; ++$i) {...}`
if ($token->isGivenKind(T_FOR)) {
$index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextMeaningfulToken($index)) + 1;
continue;
}
if (!$token->equals(';') || !$tokens[$tokens->getPrevMeaningfulToken($index)]->equals(';')) {
continue;
}
$tokens->removeLeadingWhitespace($index);
$token->clear();
}
}
示例5: 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(';'));
}
}