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


PHP Tokens::ensureWhitespaceAtIndex方法代码示例

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


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

示例1: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $count = $tokens->count();
     if ($count && !$tokens[$count - 1]->isGivenKind(array(T_INLINE_HTML, T_CLOSE_TAG, T_OPEN_TAG))) {
         $tokens->ensureWhitespaceAtIndex($count - 1, 1, $this->whitespacesConfig->getLineEnding());
     }
 }
开发者ID:friendsofphp,项目名称:php-cs-fixer,代码行数:10,代码来源:SingleBlankLineAtEofFixer.php

示例2: 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

示例3: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     for ($index = 0, $limit = $tokens->count(); $index < $limit; ++$index) {
         $token = $tokens[$index];
         if (!$token->isGivenKind(CT::T_TYPE_COLON)) {
             continue;
         }
         if ($tokens[$index - 1]->isWhitespace()) {
             $tokens[$index - 1]->clear();
         }
         ++$index;
         $tokens->ensureWhitespaceAtIndex($index, 0, ' ');
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:17,代码来源:ReturnTypeDeclarationFixer.php

示例4: 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 there is some item between braces then add `,` after it
     if ($startIndex !== $beforeEndIndex && !$beforeEndToken->equalsAny(array(',', array(T_END_HEREDOC)))) {
         $tokens->insertAt($beforeEndIndex + 1, new Token(','));
         $endToken = $tokens[$endIndex];
         if (!$endToken->isComment() && !$endToken->isWhitespace()) {
             $tokens->ensureWhitespaceAtIndex($endIndex, 1, ' ');
         }
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:24,代码来源:TrailingCommaInMultilineArrayFixer.php

示例5: fixSingleLineWhitespaceForDeclare

 /**
  * @param Tokens $tokens
  * @param int    $startBraceIndex
  */
 private function fixSingleLineWhitespaceForDeclare(Tokens $tokens, $startBraceIndex)
 {
     // fix single-line whitespace before {
     // eg: `declare(ticks=1){` => `declare(ticks=1) {`
     // eg: `declare(ticks=1)   {` => `declare(ticks=1) {`
     if (!$tokens[$startBraceIndex - 1]->isWhitespace() || $tokens[$startBraceIndex - 1]->isWhitespace(" \t")) {
         $tokens->ensureWhitespaceAtIndex($startBraceIndex - 1, 1, ' ');
     }
 }
开发者ID:amiss18,项目名称:PHP-CS-Fixer,代码行数:13,代码来源:BracesFixer.php


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