本文整理汇总了PHP中PhpCsFixer\Tokenizer\Tokens::removeTrailingWhitespace方法的典型用法代码示例。如果您正苦于以下问题:PHP Tokens::removeTrailingWhitespace方法的具体用法?PHP Tokens::removeTrailingWhitespace怎么用?PHP Tokens::removeTrailingWhitespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpCsFixer\Tokenizer\Tokens
的用法示例。
在下文中一共展示了Tokens::removeTrailingWhitespace方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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[$nextIndex]->isGivenKind(array(T_VARIABLE, T_CONSTANT_ENCAPSED_STRING, T_COMMENT))) {
$tokens->insertAt($includy['begin'] + 1, new Token(array(T_WHITESPACE, ' ')));
}
}
}
示例2: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$count = $tokens->count();
for ($index = 0; $index < $count; ++$index) {
if (!$tokens[$index]->isGivenKind(T_DECLARE)) {
continue;
}
while (!$tokens[++$index]->equals('=')) {
}
$tokens->removeLeadingWhitespace($index);
$tokens->removeTrailingWhitespace($index);
}
}
示例3: 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;
}
}
}
示例4: 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");
}
}
}
示例5: fixArray
private function fixArray(Tokens $tokens, $index)
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
if ($tokensAnalyzer->isArrayMultiLine($index)) {
return;
}
$startIndex = $index;
if ($tokens[$startIndex]->isGivenKind(T_ARRAY)) {
$startIndex = $tokens->getNextTokenOfKind($startIndex, array('('));
$endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
} else {
$endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex);
}
$beforeEndIndex = $tokens->getPrevMeaningfulToken($endIndex);
$beforeEndToken = $tokens[$beforeEndIndex];
if ($beforeEndToken->equals(',')) {
$tokens->removeTrailingWhitespace($beforeEndIndex);
$beforeEndToken->clear();
}
}
示例6: fixDeclareStatement
/**
* @param Tokens $tokens
* @param int $index
*/
private function fixDeclareStatement(Tokens $tokens, $index)
{
$tokens->removeTrailingWhitespace($index);
$startParenthesisIndex = $tokens->getNextTokenOfKind($index, array('('));
$endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex);
$startBraceIndex = $tokens->getNextTokenOfKind($endParenthesisIndex, array(';', '{'));
$startBraceToken = $tokens[$startBraceIndex];
if ($startBraceToken->equals('{')) {
$this->fixSingleLineWhitespaceForDeclare($tokens, $startBraceIndex);
}
$this->removeWhitespaceInParenthesis($tokens, $startParenthesisIndex, $endParenthesisIndex);
}
示例7: fixConcatenationToNoSpace
/**
* @param Tokens $tokens
* @param int $index index of concatenation '.' token
*/
private function fixConcatenationToNoSpace(Tokens $tokens, $index)
{
if (!$tokens[$tokens->getPrevNonWhitespace($index)]->isGivenKind(T_LNUMBER)) {
$tokens->removeLeadingWhitespace($index, " \t");
}
if (!$tokens[$tokens->getNextNonWhitespace($index)]->isGivenKind(array(T_LNUMBER, T_COMMENT, T_DOC_COMMENT))) {
$tokens->removeTrailingWhitespace($index, " \t");
}
}