本文整理汇总了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));
}
}
示例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));
}
}
示例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);
}
示例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);
}
示例5: testSplitLines
/**
* @dataProvider provideSplitLinesCases
*/
public function testSplitLines(array $expected, $input)
{
$this->assertSame($expected, Utils::splitLines($input));
}
示例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);
}
}