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


PHP Utils::splitLines方法代码示例

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


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

示例1: fixWhitespace

 private function fixWhitespace(Token $token)
 {
     $content = $token->getContent();
     if (substr_count($content, "\n") > 1) {
         $lines = Utils::splitLines($content);
         $token->setContent("\n" . end($lines));
     }
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:8,代码来源:NoEmptyLinesAfterPhpdocsFixer.php

示例2: fixWhitespace

 /**
  * Cleanup a whitespace token.
  *
  * @param Token $token
  */
 private function fixWhitespace(Token $token)
 {
     $content = $token->getContent();
     // if there is more than one new line in the whitespace, then we need to fix it
     if (substr_count($content, "\n") > 1) {
         // the final bit of the whitespace must be the next statement's indentation
         $lines = Utils::splitLines($content);
         $token->setContent("\n" . end($lines));
     }
 }
开发者ID:rafwlaz,项目名称:PHP-CS-Fixer,代码行数:15,代码来源:NoBlankLinesAfterClassOpeningFixer.php

示例3: fixDocBlock

 /**
  * Fix a given docblock.
  *
  * @param string $content
  *
  * @return string
  */
 private function fixDocBlock($content)
 {
     $lines = Utils::splitLines($content);
     $l = count($lines);
     for ($i = 0; $i < $l; ++$i) {
         $items = array();
         $matches = $this->getMatches($lines[$i]);
         if (null === $matches) {
             continue;
         }
         $current = $i;
         $items[] = $matches;
         while ($matches = $this->getMatches($lines[++$i], true)) {
             $items[] = $matches;
         }
         // compute the max length of the tag, hint and variables
         $tagMax = 0;
         $hintMax = 0;
         $varMax = 0;
         foreach ($items as $item) {
             if (null === $item['tag']) {
                 continue;
             }
             $tagMax = max($tagMax, strlen($item['tag']));
             $hintMax = max($hintMax, strlen($item['hint']));
             $varMax = max($varMax, strlen($item['var']));
         }
         $currTag = null;
         // update
         foreach ($items as $j => $item) {
             if (null === $item['tag']) {
                 if ($item['desc'][0] === '@') {
                     $lines[$current + $j] = $item['indent'] . ' * ' . $item['desc'] . "\n";
                     continue;
                 }
                 $line = $item['indent'] . ' *  ' . str_repeat(' ', $tagMax + $hintMax + $varMax + ('param' === $currTag ? 3 : 2)) . $item['desc'] . "\n";
                 $lines[$current + $j] = $line;
                 continue;
             }
             $currTag = $item['tag'];
             $line = $item['indent'] . ' * @' . $item['tag'] . str_repeat(' ', $tagMax - strlen($item['tag']) + 1) . $item['hint'];
             if (!empty($item['var'])) {
                 $line .= str_repeat(' ', $hintMax - strlen($item['hint']) + 1) . $item['var'] . (!empty($item['desc']) ? str_repeat(' ', $varMax - strlen($item['var']) + 1) . $item['desc'] . "\n" : "\n");
             } elseif (!empty($item['desc'])) {
                 $line .= str_repeat(' ', $hintMax - strlen($item['hint']) + 1) . $item['desc'] . "\n";
             } else {
                 $line .= "\n";
             }
             $lines[$current + $j] = $line;
         }
     }
     return implode($lines);
 }
开发者ID:Flesh192,项目名称:magento,代码行数:60,代码来源:PhpdocParamsFixer.php

示例4: fixDocBlock

 /**
  * Fix a given docblock.
  *
  * @param string $content
  *
  * @return string
  */
 protected function fixDocBlock($content)
 {
     $lines = Utils::splitLines($content);
     $l = count($lines);
     for ($i = 0; $i < $l; ++$i) {
         $items = [];
         $matches = $this->getMatches($lines[$i]);
         if (!$matches) {
             continue;
         }
         $current = $i;
         $items[] = $matches;
         while ($matches = $this->getMatches($lines[++$i], true)) {
             $items[] = $matches;
         }
         foreach ($items as $j => $item) {
             $pieces = explode('|', $item['hint']);
             $hints = [];
             foreach ($pieces as $piece) {
                 $hints[] = trim($piece);
             }
             $desc = trim($item['desc']);
             while (!empty($desc) && mb_substr($desc, 0, 1) === '|') {
                 $desc = trim(mb_substr($desc, 1));
                 $pos = mb_strpos($desc, ' ');
                 if ($pos > 0) {
                     $hints[] = trim(mb_substr($desc, 0, $pos));
                     $desc = trim(mb_substr($desc, $pos));
                 } else {
                     $hints[] = $desc;
                     $desc = '';
                 }
             }
             $item['hint'] = implode('|', $hints);
             $item['desc'] = $desc;
             $line = $item['indent'] . ' * @' . $item['tag'] . ' ' . $item['hint'];
             if (!empty($item['var'])) {
                 $line .= ' ' . $item['var'] . (!empty($item['desc']) ? ' ' . $item['desc'] . "\n" : "\n");
             } elseif (!empty($item['desc'])) {
                 $line .= ' ' . $item['desc'] . "\n";
             } else {
                 $line .= "\n";
             }
             $lines[$current + $j] = $line;
         }
     }
     return implode($lines);
 }
开发者ID:php-fig-rectified,项目名称:psr2r-fixer,代码行数:55,代码来源:PhpdocPipeFixer.php

示例5: testSplitLines

 /**
  * @dataProvider provideSplitLinesCases
  */
 public function testSplitLines(array $expected, $input)
 {
     $this->assertSame($expected, Utils::splitLines($input));
 }
开发者ID:kenyiu,项目名称:PHP-CS-Fixer,代码行数:7,代码来源:UtilsTest.php

示例6: __construct

 /**
  * Create a new docblock instance.
  *
  * @param string $content
  */
 public function __construct($content)
 {
     foreach (Utils::splitLines($content) as $line) {
         $this->lines[] = new Line($line);
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:11,代码来源:DocBlock.php


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