PhpParser\PrettyPrinterAbstract::pStmts PHP Method

pStmts() protected method

Pretty prints an array of nodes (statements) and indents them optionally.
protected pStmts ( array $nodes, boolean $indent = true ) : string
$nodes array Array of nodes
$indent boolean Whether to indent the printed nodes
return string Pretty printed statements
    protected function pStmts(array $nodes, $indent = true)
    {
        $result = '';
        foreach ($nodes as $node) {
            $comments = $node->getAttribute('comments', array());
            if ($comments) {
                $result .= "\n" . $this->pComments($comments);
                if ($node instanceof Stmt\Nop) {
                    continue;
                }
            }
            $result .= "\n" . $this->p($node) . ($node instanceof Expr ? ';' : '');
        }
        if ($indent) {
            return preg_replace('~\\n(?!$|' . $this->noIndentToken . ')~', "\n    ", $result);
        } else {
            return $result;
        }
    }