當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Utils::calculateTrailingWhitespaceIndent方法代碼示例

本文整理匯總了PHP中Symfony\CS\Utils::calculateTrailingWhitespaceIndent方法的典型用法代碼示例。如果您正苦於以下問題:PHP Utils::calculateTrailingWhitespaceIndent方法的具體用法?PHP Utils::calculateTrailingWhitespaceIndent怎麽用?PHP Utils::calculateTrailingWhitespaceIndent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\CS\Utils的用法示例。


在下文中一共展示了Utils::calculateTrailingWhitespaceIndent方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $tokensAnalyzer = new TokensAnalyzer($tokens);
     foreach ($tokensAnalyzer->getImportUseIndexes() as $index) {
         $indent = '';
         // if previous line ends with comment and current line starts with whitespace, use current indent
         if ($tokens[$index - 1]->isWhitespace(" \t") && $tokens[$index - 2]->isGivenKind(T_COMMENT)) {
             $indent = $tokens[$index - 1]->getContent();
         } elseif ($tokens[$index - 1]->isWhitespace()) {
             $indent = Utils::calculateTrailingWhitespaceIndent($tokens[$index - 1]);
         }
         $newline = "\n";
         // Handle insert index for inline T_COMMENT with whitespace after semicolon
         $semicolonIndex = $tokens->getNextTokenOfKind($index, array(';', '{'));
         $insertIndex = $semicolonIndex + 1;
         if ($tokens[$insertIndex]->isWhitespace(" \t") && $tokens[$insertIndex + 1]->isComment()) {
             ++$insertIndex;
         }
         // Increment insert index for inline T_COMMENT or T_DOC_COMMENT
         if ($tokens[$insertIndex]->isComment()) {
             ++$insertIndex;
         }
         $afterSemicolon = $tokens->getNextMeaningfulToken($semicolonIndex);
         if (!$tokens[$afterSemicolon]->isGivenKind(T_USE)) {
             $newline .= "\n";
         }
         if ($tokens[$insertIndex]->isWhitespace()) {
             $nextToken = $tokens[$insertIndex];
             $nextToken->setContent($newline . $indent . ltrim($nextToken->getContent()));
         } elseif ($newline && $indent) {
             $tokens->insertAt($insertIndex, new Token(array(T_WHITESPACE, $newline . $indent)));
         }
     }
 }
開發者ID:rafwlaz,項目名稱:PHP-CS-Fixer,代碼行數:37,代碼來源:SingleLineAfterImportsFixer.php

示例2: fix

 public function fix(\SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     foreach ($tokens->getImportUseIndexes() as $index) {
         $indent = '';
         if ($tokens[$index - 1]->isWhitespace(array('whitespaces' => " \t")) && $tokens[$index - 2]->isGivenKind(T_COMMENT)) {
             $indent = $tokens[$index - 1]->getContent();
         } elseif ($tokens[$index - 1]->isWhitespace()) {
             $indent = Utils::calculateTrailingWhitespaceIndent($tokens[$index - 1]);
         }
         $newline = "\n";
         $semicolonIndex = $tokens->getNextTokenOfKind($index, array(';', '{'));
         $insertIndex = $semicolonIndex + 1;
         if ($tokens[$insertIndex]->isWhitespace(array('whitespaces' => " \t")) && $tokens[$insertIndex + 1]->isComment()) {
             ++$insertIndex;
         }
         if ($tokens[$insertIndex]->isGivenKind(T_COMMENT)) {
             $newline = '';
         }
         if ($tokens[$insertIndex]->isComment()) {
             ++$insertIndex;
         }
         $afterSemicolon = $tokens->getNextMeaningfulToken($semicolonIndex);
         if (!$tokens[$afterSemicolon]->isGivenKind(T_USE)) {
             $newline .= "\n";
         }
         if ($tokens[$insertIndex]->isWhitespace()) {
             $nextToken = $tokens[$insertIndex];
             $nextToken->setContent($newline . $indent . ltrim($nextToken->getContent()));
         } else {
             $tokens->insertAt($insertIndex, new Token(array(T_WHITESPACE, $newline . $indent)));
         }
     }
     return $tokens->generateCode();
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:35,代碼來源:SingleLineAfterImportsFixer.php

示例3: fix

 public function fix(\SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $index => $token) {
         $nextIndex = $tokens->getNextMeaningfulToken($index);
         if (null === $nextIndex || $tokens[$nextIndex]->equals('}')) {
             continue;
         }
         $prevToken = $tokens[$index - 1];
         if ($prevToken->isGivenKind(T_OPEN_TAG) || $prevToken->isWhitespace(array('whitespaces' => " \t")) && !$tokens[$index - 2]->isGivenKind(T_OPEN_TAG) || $prevToken->equalsAny(array(';', '{'))) {
             continue;
         }
         $indent = '';
         if ($tokens[$nextIndex - 1]->isWhitespace()) {
             $indent = Utils::calculateTrailingWhitespaceIndent($tokens[$nextIndex - 1]);
         }
         $prevToken->setContent($this->fixWhitespaceBefore($prevToken->getContent(), $indent));
         $token->setContent($this->fixDocBlock($token->getContent(), $indent));
     }
     return $tokens->generateCode();
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:21,代碼來源:PhpdocIndentFixer.php

示例4: fix

 /**
  * @param \SplFileInfo $file
  * @param string $content
  *
  * @return string
  */
 public function fix(\SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     for ($index = $tokens->count() - 1; $index >= 0; --$index) {
         /* @var Token $token */
         $token = $tokens[$index];
         // We skip T_FOR, T_WHILE for now as they can have valid inline assignment
         if (!$token->isGivenKind([T_FOREACH, T_IF, T_SWITCH])) {
             continue;
         }
         $startIndex = $tokens->getNextMeaningfulToken($index);
         $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
         $indexEqualSign = null;
         $hasInlineAssignment = $this->hasInlineAssignment($index, $endIndex, $tokens, $indexEqualSign);
         if (!$hasInlineAssignment) {
             continue;
         }
         // Extract to own $var into line above
         $string = '';
         $var = '';
         for ($i = $startIndex + 1; $i < $endIndex; ++$i) {
             $string .= $tokens[$i]->getContent();
             if ($i < $indexEqualSign) {
                 $var .= $tokens[$i]->getContent();
             }
             $tokens[$i]->clear();
         }
         $string .= ';';
         $tokens[$i - 1]->setContent(trim($var));
         $content = $tokens[$index]->getContent();
         $indent = Utils::calculateTrailingWhitespaceIndent($tokens[$index - 1]);
         $content = $indent . $content;
         $content = $string . PHP_EOL . $content;
         $tokens[$index]->setContent($content);
     }
     return $tokens->generateCode();
 }
開發者ID:php-fig-rectified,項目名稱:psr2r-fixer,代碼行數:43,代碼來源:NoInlineAssignmentFixer.php

示例5: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $index => $token) {
         if (!$token->isGivenKind(T_DOC_COMMENT)) {
             continue;
         }
         $nextIndex = $tokens->getNextMeaningfulToken($index);
         // skip if there is no next token or if next token is block end `}`
         if (null === $nextIndex || $tokens[$nextIndex]->equals('}')) {
             continue;
         }
         $prevToken = $tokens[$index - 1];
         // ignore inline docblocks
         if ($prevToken->isGivenKind(T_OPEN_TAG) || $prevToken->isWhitespace(" \t") && !$tokens[$index - 2]->isGivenKind(T_OPEN_TAG) || $prevToken->equalsAny(array(';', '{'))) {
             continue;
         }
         $indent = '';
         if ($tokens[$nextIndex - 1]->isWhitespace()) {
             $indent = Utils::calculateTrailingWhitespaceIndent($tokens[$nextIndex - 1]);
         }
         $prevToken->setContent($this->fixWhitespaceBefore($prevToken->getContent(), $indent));
         $token->setContent($this->fixDocBlock($token->getContent(), $indent));
     }
 }
開發者ID:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:27,代碼來源:PhpdocIndentFixer.php

示例6: testCalculateTrailingWhitespaceIndentFail

 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The given token must be whitespace, got "T_STRING".
  */
 public function testCalculateTrailingWhitespaceIndentFail()
 {
     $token = new Token(array(T_STRING, 'foo'));
     Utils::calculateTrailingWhitespaceIndent($token);
 }
開發者ID:kenyiu,項目名稱:PHP-CS-Fixer,代碼行數:9,代碼來源:UtilsTest.php

示例7: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     foreach ($tokens->getImportUseIndexes() as $index) {
         $indent = '';
         // if previous line ends with comment and current line starts with whitespace, use current indent
         if ($tokens[$index - 1]->isWhitespace(array('whitespaces' => " \t")) && $tokens[$index - 2]->isGivenKind(T_COMMENT)) {
             $indent = $tokens[$index - 1]->getContent();
         } elseif ($tokens[$index - 1]->isWhitespace()) {
             $indent = Utils::calculateTrailingWhitespaceIndent($tokens[$index - 1]);
         }
         $semicolonIndex = $tokens->getNextTokenOfKind($index, array(';', array(T_CLOSE_TAG)));
         // Handle insert index for inline T_COMMENT with whitespace after semicolon
         $insertIndex = $semicolonIndex;
         if ($tokens[$semicolonIndex]->isGivenKind(T_CLOSE_TAG)) {
             if ($tokens[$insertIndex - 1]->isWhitespace()) {
                 --$insertIndex;
             }
             $tokens->insertAt($insertIndex, new Token(';'));
         }
         if ($semicolonIndex === count($tokens) - 1) {
             $tokens->insertAt($insertIndex + 1, new Token(array(T_WHITESPACE, "\n\n" . $indent)));
         } else {
             $newline = "\n";
             $tokens[$semicolonIndex]->isGivenKind(T_CLOSE_TAG) ? --$insertIndex : ++$insertIndex;
             if ($tokens[$insertIndex]->isWhitespace(array('whitespaces' => " \t")) && $tokens[$insertIndex + 1]->isComment()) {
                 ++$insertIndex;
             }
             // Do not add newline after inline T_COMMENT as it is part of T_COMMENT already
             // TODO: remove on 2.x line
             if ($tokens[$insertIndex]->isGivenKind(T_COMMENT) && false !== strpos($tokens[$insertIndex]->getContent(), "\n")) {
                 $newline = '';
             }
             // Increment insert index for inline T_COMMENT or T_DOC_COMMENT
             if ($tokens[$insertIndex]->isComment()) {
                 ++$insertIndex;
             }
             $afterSemicolon = $tokens->getNextMeaningfulToken($semicolonIndex);
             if (null === $afterSemicolon || !$tokens[$afterSemicolon]->isGivenKind(T_USE)) {
                 $newline .= "\n";
             }
             if ($tokens[$insertIndex]->isWhitespace()) {
                 $nextToken = $tokens[$insertIndex];
                 $nextMeaningfulAfterUseIndex = $tokens->getNextMeaningfulToken($insertIndex);
                 if (null !== $nextMeaningfulAfterUseIndex && $tokens[$nextMeaningfulAfterUseIndex]->isGivenKind(T_USE)) {
                     if (substr_count($nextToken->getContent(), "\n") < 2) {
                         $nextToken->setContent($newline . $indent . ltrim($nextToken->getContent()));
                     }
                 } else {
                     $nextToken->setContent($newline . $indent . ltrim($nextToken->getContent()));
                 }
             } else {
                 // TODO: remove check on 2.x line
                 if ('' !== $newline . $indent) {
                     $tokens->insertAt($insertIndex, new Token(array(T_WHITESPACE, $newline . $indent)));
                 }
             }
         }
     }
     return $tokens->generateCode();
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:64,代碼來源:SingleLineAfterImportsFixer.php


注:本文中的Symfony\CS\Utils::calculateTrailingWhitespaceIndent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。