function Printer::isMultiline
*
Parameters
Node[] $nodes: * @return array{bool, string, string}
1 call to Printer::isMultiline()
- Printer::printArrayFormatPreserving in vendor/
phpstan/ phpdoc-parser/ src/ Printer/ Printer.php - *
File
-
vendor/
phpstan/ phpdoc-parser/ src/ Printer/ Printer.php, line 720
Class
Namespace
PHPStan\PhpDocParser\PrinterCode
private function isMultiline(int $initialIndex, array $nodes, TokenIterator $originalTokens) : array {
$isMultiline = count($nodes) > 1;
$pos = $initialIndex;
$allText = '';
/** @var Node|null $node */
foreach ($nodes as $node) {
if (!$node instanceof Node) {
continue;
}
$endPos = $node->getAttribute(Attribute::END_INDEX) + 1;
$text = $originalTokens->getContentBetween($pos, $endPos);
$allText .= $text;
if (strpos($text, "\n") === false) {
// We require that a newline is present between *every* item. If the formatting
// is inconsistent, with only some items having newlines, we don't consider it
// as multiline
$isMultiline = false;
}
$pos = $endPos;
}
$c = preg_match_all('~\\n(?<before>[\\x09\\x20]*)\\*(?<after>\\x20*)~', $allText, $matches, PREG_SET_ORDER);
if ($c === 0) {
return [
$isMultiline,
'',
'',
];
}
$before = '';
$after = '';
foreach ($matches as $match) {
if (strlen($match['before']) > strlen($before)) {
$before = $match['before'];
}
if (strlen($match['after']) <= strlen($after)) {
continue;
}
$after = $match['after'];
}
return [
$isMultiline,
$before,
$after,
];
}