Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Printer.php

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

Printer
Inspired by https://github.com/nikic/PHP-Parser/tree/36a6dcd04e7b0285e8f0868f44bd49…

Namespace

PHPStan\PhpDocParser\Printer

Code

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,
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal