/** * Pretty prints an array of nodes and implodes the printed values with commas. * * @param \PhpParser\Node[] $nodes Array of Nodes to be printed * * @return string Comma separated pretty printed nodes */ protected function pParameterNodes(array $nodes) { $startLine = ''; $multiLine = FALSE; if (isset($nodes[0]) && $nodes[0]->hasAttribute('startLine')) { $startLine = reset($nodes)->getAttribute('startLine'); $endLine = end($nodes)->getAttribute('endLine'); if ($startLine != $endLine) { $multiLine = TRUE; } } if (!$multiLine) { return parent::pCommaSeparated($nodes); } $printedNodes = ''; foreach ($nodes as $node) { $glueToken = ", "; if ($node->getAttribute('startLine') != $startLine) { $glueToken = ',' . LF; $startLine = $node->getAttribute('startLine'); } if (!empty($printedNodes)) { $printedNodes .= $glueToken . $this->p($node); } else { $printedNodes .= $this->p($node); } } return preg_replace('~\\n(?!$|' . $this->noIndentToken . ')~', LF . $this->indentToken, $printedNodes); }
protected function pCommaSeparatedLines(array $nodes, $prefix = '', $suffix = '', $trailingComma = false) { $arr = parent::pCommaSeparated($nodes); if ($this->needsWrapping($arr)) { $arr = "\n" . $this->pImplode($nodes, ",\n") . ($trailingComma ? ',' : '') . "\n"; } return $prefix . preg_replace('~\\n(?!$|\\n|' . $this->noIndentToken . ')~', "\n" . $this->indentation, $arr) . $suffix; }