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


PHP Tokens::getNextNonWhitespace方法代码示例

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


在下文中一共展示了Tokens::getNextNonWhitespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fix

 /**
  * Replace all `else if` (T_ELSE T_IF) with `elseif` (T_ELSEIF).
  *
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $index => $token) {
         if (!$token->isGivenKind(T_ELSE)) {
             continue;
         }
         $nextIndex = $tokens->getNextNonWhitespace($index);
         $nextToken = $tokens[$nextIndex];
         // if next meaning token is not T_IF - continue searching, this is not the case for fixing
         if (!$nextToken->isGivenKind(T_IF)) {
             continue;
         }
         // now we have T_ELSE following by T_IF so we could fix this
         // 1. clear whitespaces between T_ELSE and T_IF
         $tokens[$index + 1]->clear();
         // 2. change token from T_ELSE into T_ELSEIF
         $tokens->overrideAt($index, array(T_ELSEIF, 'elseif'));
         // 3. clear succeeding T_IF
         $nextToken->clear();
     }
     // handle `T_ELSE T_WHITESPACE T_IF` treated as single `T_ELSEIF` by HHVM
     // see https://github.com/facebook/hhvm/issues/4796
     if (defined('HHVM_VERSION')) {
         foreach ($tokens->findGivenKind(T_ELSEIF) as $token) {
             $token->setContent('elseif');
         }
     }
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:33,代码来源:ElseifFixer.php

示例2: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     for ($index = $tokens->count() - 3; $index > 0; --$index) {
         $token = $tokens[$index];
         if (!$token->isGivenKind(T_NEW)) {
             continue;
         }
         $nextIndex = $tokens->getNextTokenOfKind($index, array(':', ';', ',', '(', ')', '[', ']', array(T_CLOSE_TAG), array(CT_ARRAY_SQUARE_BRACE_OPEN), array(CT_ARRAY_SQUARE_BRACE_CLOSE), array(CT_BRACE_CLASS_INSTANTIATION_OPEN), array(CT_BRACE_CLASS_INSTANTIATION_CLOSE)));
         $nextToken = $tokens[$nextIndex];
         // entrance into array index syntax - need to look for exit
         while ($nextToken->equals('[')) {
             $nextIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $nextIndex) + 1;
             $nextToken = $tokens[$nextIndex];
         }
         // new statement has a gap in it - advance to the next token
         if ($nextToken->isWhitespace()) {
             $nextIndex = $tokens->getNextNonWhitespace($nextIndex);
             $nextToken = $tokens[$nextIndex];
         }
         // new statement with () - nothing to do
         if ($nextToken->equals('(')) {
             continue;
         }
         $meaningBeforeNextIndex = $tokens->getPrevMeaningfulToken($nextIndex);
         $tokens->insertAt($meaningBeforeNextIndex + 1, array(new Token('('), new Token(')')));
     }
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:30,代码来源:NewWithBracesFixer.php

示例3: fixLineBreaksPerImportGroup

 /**
  * Fix the line breaks per group.
  *
  * For each use token reach the nearest ; and ensure every
  * token after has one \n before next non empty token (next line).
  * It skips the first pass from the bottom.
  *
  * @param Tokens $tokens
  * @param array  $uses
  */
 private function fixLineBreaksPerImportGroup(Tokens $tokens, array $uses)
 {
     foreach ($uses as $index) {
         $endIndex = $tokens->getNextTokenOfKind($index, array(';'));
         $afterSemicolonIndex = $tokens->getNextNonWhitespace($endIndex);
         if (null !== $afterSemicolonIndex && !$tokens[$afterSemicolonIndex]->isGivenKind(T_USE)) {
             continue;
         }
         $nextToken = $tokens[$endIndex + 1];
         if ($nextToken->isWhitespace()) {
             $nextToken->setContent(preg_replace('/\\n{2,}/', "\n", $nextToken->getContent()));
         }
     }
 }
开发者ID:cryode,项目名称:PHP-CS-Fixer,代码行数:24,代码来源:NoBlankLinesBetweenUsesFixer.php

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

示例5: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     static $forbiddenSuccessors = array(T_DOC_COMMENT, T_COMMENT, T_WHITESPACE, T_RETURN, T_THROW, T_GOTO, T_CONTINUE, T_BREAK);
     foreach ($tokens as $index => $token) {
         if (!$token->isGivenKind(T_DOC_COMMENT)) {
             continue;
         }
         // get the next non-whitespace token inc comments, provided
         // that there is whitespace between it and the current token
         $next = $tokens->getNextNonWhitespace($index);
         if ($index + 2 === $next && false === $tokens[$next]->isGivenKind($forbiddenSuccessors)) {
             $this->fixWhitespace($tokens[$index + 1]);
         }
     }
 }
开发者ID:friendsofphp,项目名称:php-cs-fixer,代码行数:18,代码来源:NoBlankLinesAfterPhpdocFixer.php

示例6: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $tokensAnalyzer = new TokensAnalyzer($tokens);
     for ($index = $tokens->count() - 1; $index >= 0; --$index) {
         $token = $tokens[$index];
         if (!$token->isGivenKind(T_FUNCTION)) {
             continue;
         }
         $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('{')) {
             // fix single-line whitespace before {
             // eg: `function foo(){}` => `function foo() {}`
             // eg: `function foo()   {}` => `function foo() {}`
             if (!$tokens[$startBraceIndex - 1]->isWhitespace() || $tokens[$startBraceIndex - 1]->isWhitespace($this->singleLineWhitespaceOptions)) {
                 $tokens->ensureWhitespaceAtIndex($startBraceIndex - 1, 1, ' ');
             }
         }
         $afterParenthesisIndex = $tokens->getNextNonWhitespace($endParenthesisIndex);
         $afterParenthesisToken = $tokens[$afterParenthesisIndex];
         if ($afterParenthesisToken->isGivenKind(CT_USE_LAMBDA)) {
             $useStartParenthesisIndex = $tokens->getNextTokenOfKind($afterParenthesisIndex, array('('));
             $useEndParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $useStartParenthesisIndex);
             // fix whitespace after CT_USE_LAMBDA
             $tokens->ensureWhitespaceAtIndex($afterParenthesisIndex + 1, 0, ' ');
             // remove single-line edge whitespaces inside use parentheses
             $this->fixParenthesisInnerEdge($tokens, $useStartParenthesisIndex, $useEndParenthesisIndex);
             // fix whitespace before CT_USE_LAMBDA
             $tokens->ensureWhitespaceAtIndex($afterParenthesisIndex - 1, 1, ' ');
         }
         // remove single-line edge whitespaces inside parameters list parentheses
         $this->fixParenthesisInnerEdge($tokens, $startParenthesisIndex, $endParenthesisIndex);
         if (!$tokensAnalyzer->isLambda($index)) {
             // remove whitespace before (
             // eg: `function foo () {}` => `function foo() {}`
             if ($tokens[$startParenthesisIndex - 1]->isWhitespace()) {
                 $tokens[$startParenthesisIndex - 1]->clear();
             }
         }
         // fix whitespace after T_FUNCTION
         // eg: `function     foo() {}` => `function foo() {}`
         $tokens->ensureWhitespaceAtIndex($index + 1, 0, ' ');
     }
 }
开发者ID:amiss18,项目名称:PHP-CS-Fixer,代码行数:49,代码来源:FunctionDeclarationFixer.php

示例7: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $foundNamespace = $tokens->findGivenKind(T_NAMESPACE);
     if (empty($foundNamespace)) {
         return;
     }
     $tokensAnalyzer = new TokensAnalyzer($tokens);
     $firstNamespaceIdx = key($foundNamespace);
     $usesIdxs = $tokensAnalyzer->getImportUseIndexes();
     foreach ($usesIdxs as $idx) {
         if ($idx < $firstNamespaceIdx) {
             continue;
         }
         $nextTokenIdx = $tokens->getNextNonWhitespace($idx);
         $nextToken = $tokens[$nextTokenIdx];
         if ($nextToken->isGivenKind(T_NS_SEPARATOR)) {
             $nextToken->clear();
         }
     }
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:23,代码来源:NoLeadingImportSlashFixer.php

示例8: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $tokensAnalyzer = new TokensAnalyzer($tokens);
     for ($index = $tokens->count() - 1; $index >= 0; --$index) {
         if (!$tokensAnalyzer->isBinaryOperator($index)) {
             continue;
         }
         // skip `declare(foo ==bar)`
         $prevMeaningfulIndex = $tokens->getPrevMeaningfulToken($index);
         if ($tokens[$prevMeaningfulIndex]->isGivenKind(T_STRING)) {
             $prevMeaningfulIndex = $tokens->getPrevMeaningfulToken($prevMeaningfulIndex);
             if ($tokens[$prevMeaningfulIndex]->equals('(')) {
                 $prevMeaningfulIndex = $tokens->getPrevMeaningfulToken($prevMeaningfulIndex);
                 if ($tokens[$prevMeaningfulIndex]->isGivenKind(T_DECLARE)) {
                     continue;
                 }
             }
         }
         // fix white space after operator
         if ($tokens[$index + 1]->isWhitespace()) {
             $content = $tokens[$index + 1]->getContent();
             if (' ' !== $content && false === strpos($content, "\n") && !$tokens[$tokens->getNextNonWhitespace($index + 1)]->isComment()) {
                 $tokens[$index + 1]->setContent(' ');
             }
         } else {
             $tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, ' ')));
         }
         // fix white space before operator
         if ($tokens[$index - 1]->isWhitespace()) {
             $content = $tokens[$index - 1]->getContent();
             if (' ' !== $content && false === strpos($content, "\n") && !$tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) {
                 $tokens[$index - 1]->setContent(' ');
             }
         } else {
             $tokens->insertAt($index, new Token(array(T_WHITESPACE, ' ')));
         }
         --$index;
         // skip check for binary operator on the whitespace token that is fixed.
     }
 }
开发者ID:phansys,项目名称:PHP-CS-Fixer,代码行数:43,代码来源:BinaryOperatorSpacesFixer.php

示例9: fixWhiteSpaceAroundOperator

 private function fixWhiteSpaceAroundOperator(Tokens $tokens, $index)
 {
     // do not change the alignment of `=>` or `=`, see `(un)align_double_arrow`, `(un)align_equals`
     $preserveAlignment = $tokens[$index]->isGivenKind(T_DOUBLE_ARROW) || $tokens[$index]->equals('=');
     // fix white space after operator
     if ($tokens[$index + 1]->isWhitespace()) {
         $content = $tokens[$index + 1]->getContent();
         if (!$preserveAlignment && ' ' !== $content && false === strpos($content, "\n") && !$tokens[$tokens->getNextNonWhitespace($index + 1)]->isComment()) {
             $tokens[$index + 1]->setContent(' ');
         }
     } else {
         $tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, ' ')));
     }
     // fix white space before operator
     if ($tokens[$index - 1]->isWhitespace()) {
         $content = $tokens[$index - 1]->getContent();
         if (!$preserveAlignment && ' ' !== $content && false === strpos($content, "\n") && !$tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) {
             $tokens[$index - 1]->setContent(' ');
         }
     } else {
         $tokens->insertAt($index, new Token(array(T_WHITESPACE, ' ')));
     }
 }
开发者ID:GrahamForks,项目名称:PHP-CS-Fixer,代码行数:23,代码来源:BinaryOperatorSpacesFixer.php

示例10: fixArray

 /**
  * Method to trim leading/trailing whitespace within single line arrays.
  *
  * @param Tokens $tokens
  * @param int    $index
  */
 private static function fixArray(Tokens $tokens, $index)
 {
     $startIndex = $index;
     if ($tokens[$startIndex]->isGivenKind(T_ARRAY)) {
         $startIndex = $tokens->getNextMeaningfulToken($startIndex);
         $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
     } else {
         $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex);
     }
     $nextToken = $tokens[$startIndex + 1];
     $nextNonWhitespaceIndex = $tokens->getNextNonWhitespace($startIndex);
     $nextNonWhitespaceToken = $tokens[$nextNonWhitespaceIndex];
     $tokenAfterNextNonWhitespaceToken = $tokens[$nextNonWhitespaceIndex + 1];
     $prevToken = $tokens[$endIndex - 1];
     $prevNonWhitespaceIndex = $tokens->getPrevNonWhitespace($endIndex);
     $prevNonWhitespaceToken = $tokens[$prevNonWhitespaceIndex];
     if ($nextToken->isWhitespace(" \t") && (!$nextNonWhitespaceToken->isComment() || $nextNonWhitespaceIndex === $prevNonWhitespaceIndex || $tokenAfterNextNonWhitespaceToken->isWhitespace(" \t") || '/*' === substr($nextNonWhitespaceToken->getContent(), 0, 2))) {
         $nextToken->clear();
     }
     if ($prevToken->isWhitespace(" \t") && !$prevNonWhitespaceToken->equals(',')) {
         $prevToken->clear();
     }
 }
开发者ID:friendsofphp,项目名称:php-cs-fixer,代码行数:29,代码来源:TrimArraySpacesFixer.php

示例11: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     static $nextTokenKinds = null;
     if (null === $nextTokenKinds) {
         $nextTokenKinds = array('?', ';', ',', '(', ')', '[', ']', ':', '<', '>', '+', '-', '*', '/', '%', '&', '^', '|', array(T_IS_SMALLER_OR_EQUAL), array(T_IS_GREATER_OR_EQUAL), array(T_IS_EQUAL), array(T_IS_NOT_EQUAL), array(T_IS_IDENTICAL), array(T_IS_NOT_IDENTICAL), array(T_CLOSE_TAG), array(T_LOGICAL_AND), array(T_LOGICAL_OR), array(T_LOGICAL_XOR), array(T_BOOLEAN_AND), array(T_BOOLEAN_OR), array(T_INC), array(T_DEC), array(T_SL), array(T_SR), array(T_INSTANCEOF), array(T_AS), array(T_DOUBLE_ARROW), array(CT_ARRAY_SQUARE_BRACE_OPEN), array(CT_ARRAY_SQUARE_BRACE_CLOSE), array(CT_BRACE_CLASS_INSTANTIATION_OPEN), array(CT_BRACE_CLASS_INSTANTIATION_CLOSE));
         if (defined('T_POW')) {
             $nextTokenKinds[] = array(T_POW);
         }
         if (defined('T_SPACESHIP')) {
             $nextTokenKinds[] = array(T_SPACESHIP);
         }
     }
     for ($index = $tokens->count() - 3; $index > 0; --$index) {
         $token = $tokens[$index];
         if (!$token->isGivenKind(T_NEW)) {
             continue;
         }
         $nextIndex = $tokens->getNextTokenOfKind($index, $nextTokenKinds);
         $nextToken = $tokens[$nextIndex];
         // entrance into array index syntax - need to look for exit
         while ($nextToken->equals('[')) {
             $nextIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $nextIndex) + 1;
             $nextToken = $tokens[$nextIndex];
         }
         // new statement has a gap in it - advance to the next token
         if ($nextToken->isWhitespace()) {
             $nextIndex = $tokens->getNextNonWhitespace($nextIndex);
             $nextToken = $tokens[$nextIndex];
         }
         // new statement with () - nothing to do
         if ($nextToken->equals('(')) {
             continue;
         }
         $meaningBeforeNextIndex = $tokens->getPrevMeaningfulToken($nextIndex);
         $tokens->insertAt($meaningBeforeNextIndex + 1, array(new Token('('), new Token(')')));
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:40,代码来源:NewWithBracesFixer.php

示例12: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $ternaryLevel = 0;
     foreach ($tokens as $index => $token) {
         if ($token->isArray()) {
             continue;
         }
         if ($token->equals('?')) {
             ++$ternaryLevel;
             $nextNonWhitespaceIndex = $tokens->getNextNonWhitespace($index);
             $nextNonWhitespaceToken = $tokens[$nextNonWhitespaceIndex];
             if ($nextNonWhitespaceToken->equals(':')) {
                 // for `$a ?: $b` remove spaces between `?` and `:`
                 if ($tokens[$index + 1]->isWhitespace()) {
                     $tokens[$index + 1]->clear();
                 }
             } else {
                 // for `$a ? $b : $c` ensure space after `?`
                 $this->ensureWhitespaceExistence($tokens, $index + 1, true);
             }
             // for `$a ? $b : $c` ensure space before `?`
             $this->ensureWhitespaceExistence($tokens, $index - 1, false);
             continue;
         }
         if ($ternaryLevel && $token->equals(':')) {
             // for `$a ? $b : $c` ensure space after `:`
             $this->ensureWhitespaceExistence($tokens, $index + 1, true);
             $prevNonWhitespaceToken = $tokens[$tokens->getPrevNonWhitespace($index)];
             if (!$prevNonWhitespaceToken->equals('?')) {
                 // for `$a ? $b : $c` ensure space before `:`
                 $this->ensureWhitespaceExistence($tokens, $index - 1, false);
             }
             --$ternaryLevel;
         }
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:39,代码来源:TernaryOperatorSpacesFixer.php

示例13: findParenthesisEnd

 /**
  * @param Tokens $tokens
  * @param int    $structureTokenIndex
  *
  * @return int
  */
 private function findParenthesisEnd(Tokens $tokens, $structureTokenIndex)
 {
     $nextIndex = $tokens->getNextNonWhitespace($structureTokenIndex);
     $nextToken = $tokens[$nextIndex];
     // return if next token is not opening parenthesis
     if (!$nextToken->equals('(')) {
         return $structureTokenIndex;
     }
     return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextIndex);
 }
开发者ID:amiss18,项目名称:PHP-CS-Fixer,代码行数:16,代码来源:BracesFixer.php

示例14: fixSpaceBelowMethod

 /**
  * @param Tokens $tokens
  * @param int    $classEnd
  * @param int    $methodEnd
  */
 private function fixSpaceBelowMethod(Tokens $tokens, $classEnd, $methodEnd)
 {
     $nextNotWhite = $tokens->getNextNonWhitespace($methodEnd);
     $this->correctLineBreaks($tokens, $methodEnd, $nextNotWhite, $nextNotWhite === $classEnd ? 1 : 2);
 }
开发者ID:SEOshop,项目名称:PHP-CS-Fixer,代码行数:10,代码来源:MethodSeparationFixer.php

示例15: findHeaderCommentInsertionIndex

 /**
  * Find the index where the header comment must be inserted.
  *
  * @param Tokens $tokens
  *
  * @return int
  */
 private function findHeaderCommentInsertionIndex(Tokens $tokens)
 {
     $index = $tokens->getNextNonWhitespace(0);
     if (null === $index) {
         // empty file, insert at the end
         $index = $tokens->getSize();
     }
     return $index;
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:16,代码来源:HeaderCommentFixer.php


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