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


PHP Tokens::removeLeadingWhitespace方法代码示例

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


在下文中一共展示了Tokens::removeLeadingWhitespace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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, ' ')));
         }
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:30,代码来源:IncludeFixer.php

示例2: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $index => $token) {
         if (!$token->equalsAny(array('[', array(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN)))) {
             continue;
         }
         if (in_array('inside', $this->configuration, true)) {
             if ($token->equals('[')) {
                 $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index);
             } else {
                 $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE, $index);
             }
             // remove space after opening `[` or `{`
             $this->removeWhitespaceToken($tokens[$index + 1]);
             // remove space before closing `]` or `}`
             $this->removeWhitespaceToken($tokens[$endIndex - 1]);
         }
         if (in_array('outside', $this->configuration, true)) {
             $prevNonWhitespaceIndex = $tokens->getPrevNonWhitespace($index);
             if ($tokens[$prevNonWhitespaceIndex]->isComment()) {
                 continue;
             }
             $tokens->removeLeadingWhitespace($index);
         }
     }
 }
开发者ID:friendsofphp,项目名称:php-cs-fixer,代码行数:29,代码来源:NoSpacesAroundOffsetFixer.php

示例3: 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");
     }
 }
开发者ID:friendsofphp,项目名称:php-cs-fixer,代码行数:13,代码来源:ConcatSpaceFixer.php

示例4: 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);
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:16,代码来源:DeclareEqualNormalizeFixer.php

示例5: 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;
         }
     }
 }
开发者ID:cryode,项目名称:PHP-CS-Fixer,代码行数:17,代码来源:UnaryOperatorSpacesFixer.php

示例6: 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");
         }
     }
 }
开发者ID:cryode,项目名称:PHP-CS-Fixer,代码行数:17,代码来源:ConcatWithoutSpacesFixer.php

示例7: 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();
     }
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:20,代码来源:NoDuplicateSemicolonsFixer.php

示例8: 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(';'));
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:21,代码来源:NoClosingTagFixer.php


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