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


PHP Tokens::getNextNonWhitespace方法代码示例

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


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

示例1: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $namespace = false;
     $classyName = null;
     $classyIndex = 0;
     foreach ($tokens as $index => $token) {
         if ($token->isGivenKind(T_NAMESPACE)) {
             if (false !== $namespace) {
                 return;
             }
             $namespace = true;
         } elseif ($token->isClassy()) {
             if (null !== $classyName) {
                 return;
             }
             $classyIndex = $tokens->getNextNonWhitespace($index);
             $classyName = $tokens[$classyIndex]->getContent();
         }
     }
     if (null === $classyName) {
         return;
     }
     if (false !== $namespace) {
         $filename = basename(strtr($file->getRealPath(), '\\', '/'), '.php');
         if ($classyName !== $filename) {
             $tokens[$classyIndex]->setContent($filename);
         }
     } else {
         $normClass = strtr($classyName, '_', '/');
         $filename = substr(strtr($file->getRealPath(), '\\', '/'), -strlen($normClass) - 4, -4);
         if ($normClass !== $filename && strtolower($normClass) === strtolower($filename)) {
             $tokens[$classyIndex]->setContent(strtr($filename, '/', '_'));
         }
     }
 }
开发者ID:stof,项目名称:PHP-CS-Fixer-1,代码行数:38,代码来源:Psr4Fixer.php

示例2: 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:skillberto,项目名称:PHP-CS-Fixer,代码行数:33,代码来源:ElseifFixer.php

示例3: 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->getNextNonWhitespace($includy['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, ' ')));
         }
     }
 }
开发者ID:bgotink,项目名称:PHP-CS-Fixer,代码行数:30,代码来源:IncludeFixer.php

示例4: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     for ($index = $tokens->count() - 1; $index >= 0; --$index) {
         $token = $tokens[$index];
         if (!$token->isGivenKind(T_NEW)) {
             continue;
         }
         $nextIndex = $tokens->getNextTokenOfKind($index, array(':', ';', ',', '(', ')', '[', ']', 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->isGivenKind(T_WHITESPACE)) {
             $nextIndex = $tokens->getNextNonWhitespace($nextIndex);
             $nextToken = $tokens[$nextIndex];
         }
         // new statement with () - nothing to do
         if ($nextToken->equals('(')) {
             continue;
         }
         $meaningBeforeNextIndex = $tokens->getPrevNonWhitespace($nextIndex);
         $tokens->insertAt($meaningBeforeNextIndex + 1, array(new Token('('), new Token(')')));
     }
 }
开发者ID:nazimodi,项目名称:PHP-CS-Fixer,代码行数:30,代码来源:NewWithBracesFixer.php

示例5: findHeaderCommentInsertionIndex

 private function findHeaderCommentInsertionIndex(Tokens $tokens)
 {
     $index = $tokens->getNextNonWhitespace(0);
     if (null === $index) {
         $index = $tokens->getSize();
     }
     return $index;
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:8,代码来源:HeaderCommentFixer.php

示例6: 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];
 }
开发者ID:nazimodi,项目名称:PHP-CS-Fixer,代码行数:18,代码来源:PhpUnitConstructFixer.php

示例7: 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:rafwlaz,项目名称:PHP-CS-Fixer,代码行数:24,代码来源:RemoveLinesBetweenUsesFixer.php

示例8: 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:rafwlaz,项目名称:PHP-CS-Fixer,代码行数:17,代码来源:ConcatWithoutSpacesFixer.php

示例9: extract

 /**
  * @param Tokens $tokens
  *
  * @throws ExtractionException
  *
  * @return string
  */
 public function extract(Tokens $tokens)
 {
     $classyName = null;
     foreach ($tokens as $index => $token) {
         if ($token->isClassy()) {
             $classyIndex = $tokens->getNextNonWhitespace($index);
             $classyName = $tokens[$classyIndex]->getContent();
         }
     }
     if (null === $classyName) {
         throw new ExtractionException('No way to parse class name of this class');
     }
     return $classyName;
 }
开发者ID:akeneo,项目名称:php-coupling-detector,代码行数:21,代码来源:ClassNameExtractor.php

示例10: 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:rafwlaz,项目名称:PHP-CS-Fixer,代码行数:18,代码来源:NoEmptyLinesAfterPhpdocsFixer.php

示例11: extract

 /**
  * @param Tokens $tokens
  *
  * @throws ExtractionException
  *
  * @return string
  */
 public function extract(Tokens $tokens)
 {
     $namespace = null;
     foreach ($tokens as $index => $token) {
         if ($token->isGivenKind(T_NAMESPACE)) {
             $namespaceIndex = $tokens->getNextNonWhitespace($index);
             $namespaceEndIndex = $tokens->getNextTokenOfKind($index, array(';'));
             $namespace = trim($tokens->generatePartialCode($namespaceIndex, $namespaceEndIndex - 1));
         }
     }
     if (null === $namespace) {
         throw new ExtractionException('No way to parse the namespace of this class');
     }
     return $namespace;
 }
开发者ID:akeneo,项目名称:php-coupling-detector,代码行数:22,代码来源:NamespaceExtractor.php

示例12: 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:skillberto,项目名称:PHP-CS-Fixer,代码行数:49,代码来源:FunctionDeclarationFixer.php

示例13: 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];
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:20,代码来源:PhpUnitConstructFixer.php

示例14: 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:skillberto,项目名称:PHP-CS-Fixer,代码行数:23,代码来源:RemoveLeadingSlashUseFixer.php

示例15: findIncludies

 private function findIncludies(Tokens $tokens)
 {
     static $includyTokenKinds = array(T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE);
     $includies = array();
     foreach ($tokens->findGivenKind($includyTokenKinds) as $includyTokens) {
         foreach ($includyTokens as $index => $token) {
             $includy = array('begin' => $index, 'braces' => null, 'end' => $tokens->getNextTokenOfKind($index, array(';')));
             // Don't remove when the statement is wrapped. include is also legal as function parameter
             // but requires being wrapped then
             if (!$tokens[$tokens->getPrevNonWhitespace($index)]->equals('(')) {
                 $nextTokenIndex = $tokens->getNextNonWhitespace($index);
                 $nextToken = $tokens[$nextTokenIndex];
                 if ($nextToken->equals('(')) {
                     $includy['braces'] = array('open' => $nextTokenIndex, 'close' => $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextTokenIndex));
                 }
             }
             $includies[] = $includy;
         }
     }
     return $includies;
 }
开发者ID:wjaspers,项目名称:PHP-CS-Fixer,代码行数:21,代码来源:IncludeFixer.php


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