Pretty prints an array of nodes (statements) and indents them optionally.

@param \PhpParser\Node[] $nodes  Array of nodes
@param bool   $indent Whether to indent the printed nodes

@return string Pretty printed statements
540508
protected function pStmts(array $nodes, $indent = true)
    {
        $result = '';

        foreach ($nodes as $node) {
            $row = "";

            $cur_ln = $this->cur_ln;

            $comments = $node->getAttribute('comments', array());
            $comments = !empty($comments) ? ($this->pComments($node->getAttribute('comments', array())) . "\n") : "";
            $this->cur_ln += substr_count($comments, "\n");

            if ($node->getLine() > $this->cur_ln) {
                $row .= str_repeat("\n", $node->getLine() - $this->cur_ln);
                $this->cur_ln += substr_count($row, "\n");
            }

            $row .= $comments
                . $this->p($node)
                . ($node instanceof \PhpParser\Node\Expr ? ';' : '');

            $this->cur_ln = $cur_ln + substr_count($row, "\n"); // get rid of cur_ln modifications in deeper context

            $result .= $row;
        }

        if ($indent) {
            return preg_replace('~\n(?!$|' . $this->noIndentToken . ')~', "\n    ", $result);
        } else {
            return $result;
        }
    }
1155653
function compile($indent) {
		$function_name = $this->function_name( $this->name ) ;
		
		// Build the typestack
		$typestack = array(); $class=$this;
		do {
			$typestack[] = $this->function_name($class->name);
		}
		while($class = $class->extends);

		$typestack = "array('" . implode("','", $typestack) . "')";
		
		// Build an array of additional arguments to add to result node (if any)
		if (empty($this->arguments)) {
			$arguments = 'null';
		}
		else {
			$arguments = "array(";
			foreach ($this->arguments as $k=>$v) { $arguments .= "'$k' => '$v'"; }
			$arguments .= ")";
		}
		
		$match = PHPBuilder::build() ;
		
		$match->l("protected \$match_{$function_name}_typestack = $typestack;");

		$match->b( "function match_{$function_name} (\$stack = array())",
			'$matchrule = "'.$function_name.'"; $result = $this->construct($matchrule, $matchrule, '.$arguments.');',
			$this->parsed->compile()->replace(array(
				'MATCH' => 'return $this->finalise($result);',
				'FAIL' => 'return FALSE;'
			))
		);

		$functions = array() ;
		foreach( $this->functions as $name => $function ) {
			$function_name = $this->function_name( preg_match( '/^_/', $name ) ? $this->name.$name : $this->name.'_'.$name ) ;
			$functions[] = implode( PHP_EOL, array(
				'function ' . $function_name . ' ' . $function
			));
		}

		// print_r( $match ) ; return '' ;
		return $match->render(NULL, $indent) . PHP_EOL . PHP_EOL . implode( PHP_EOL, $functions ) ;
	}
274764
private function prepareNodesTree(
        $nodes,
        $webspaceKey,
        $languageCode,
        $complete = true,
        $excludeGhosts = false,
        $maxDepth = 1,
        $currentDepth = 0
    ) {
        ++$currentDepth;

        $results = [];
        foreach ($nodes as $node) {
            $result = $this->prepareNode($node, $webspaceKey, $languageCode, 1, $complete, $excludeGhosts);
            if (null !== $maxDepth &&
                $currentDepth < $maxDepth &&
                $node->getHasChildren() &&
                null != $node->getChildren()
            ) {
                $result['_embedded']['nodes'] = $this->prepareNodesTree(
                    $node->getChildren(),
                    $webspaceKey,
                    $languageCode,
                    $complete,
                    $excludeGhosts,
                    $maxDepth,
                    $currentDepth
                );
            }
            $results[] = $result;
        }

        return $results;
    }
357585
public function write_files($files, $indent) {
        if (empty($files)) {
            return '';
        }
        $string = '';
        foreach ($files as $file) {
            if ($file->is_directory()) {
                continue;
            }
            $string .= str_repeat('  ', $indent);
            $string .= '<file name="' . $file->get_filename() . '" encoding="base64">';
            $string .= base64_encode($file->get_content());
            $string .= "</file>\n";
        }
        return $string;
    }
1139357
protected function _strip(array $nodes, array $wrapper = array()) {
        $parsed = '';

        if (!$nodes) {
            return $parsed;
        }

        foreach ($nodes as $node) {
            if (is_string($node)) {
                if (!$wrapper) {
                    $parsed .= $this->convertLineBreaks($node);
                } else {
                    $parsed .= $node;
                }
            } else {
                $parsed .= $this->getFilterByTag($node['tag'])->strip($node, $this->_strip($node['children'], $node));
            }
        }

        return $parsed;
    }
130481
public function toString($indent = null)
    {
        $indent = ($indent !== null)
                ? $this->getWhitespace($indent)
                : $this->getIndent();

        $return    = $this->prefix;
        $keys      = array_keys($this->container);
        $lastIndex = end($keys);
        foreach ($this->container as $index => $item) {
            $item = array_merge($this->defaultParams, (array) $item);
            $return .= vsprintf($this->wrapper, $item);
            if ($index !== $lastIndex) {
                $return .= $this->separator;
            }
        }
        $return .= $this->postfix;

        return preg_replace("/(\r\n?|\n)[ ]*/", '$1' . $indent, $return);
    }
677346
public function render($indent = "\t")
    {
        $html = '';
        foreach(self::$storage as $meta) {
            $html .= $indent . $meta->render() . PHP_EOL;
        }
        
        return $html;
    }
274264
protected function indentArray(array $elements) {
		return self::INDENTATION . \str_replace(PHP_EOL, PHP_EOL . self::INDENTATION, \implode(PHP_EOL, $elements));
	}
950152
public function append($lines, $newline = true, $indentOffset = 0)
    {
        $this->_buffer[] = trim($lines) ? ($this->_getIndentationString($indentOffset) . $lines) : $lines;
        if ($newline) {
            $this->_buffer[] = $this->newLineStr;
        }

        return $this;
    }
416012
public function setNodesColor($Nodes, array $Settings = [])
    {
        if (is_array($Nodes)) {
            foreach ($Nodes as $Key => $NodeID) {
                if (isset($this->Data[$NodeID])) {
                    if (isset($Settings["R"])) {
                        $this->Data[$NodeID]["R"] = $Settings["R"];
                    }
                    if (isset($Settings["G"])) {
                        $this->Data[$NodeID]["G"] = $Settings["G"];
                    }
                    if (isset($Settings["B"])) {
                        $this->Data[$NodeID]["B"] = $Settings["B"];
                    }
                    if (isset($Settings["Alpha"])) {
                        $this->Data[$NodeID]["Alpha"] = $Settings["Alpha"];
                    }
                    if (isset($Settings["BorderR"])) {
                        $this->Data[$NodeID]["BorderR"] = $Settings["BorderR"];
                    }
                    if (isset($Settings["BorderG"])) {
                        $this->Data[$NodeID]["BorderG"] = $Settings["BorderG"];
                    }
                    if (isset($Settings["BorderB"])) {
                        $this->Data[$NodeID]["BorderB"] = $Settings["BorderB"];
                    }
                    if (isset($Settings["BorderAlpha"])) {
                        $this->Data[$NodeID]["BorderAlpha"] = $Settings["BorderAlpha"];
                    }
                    if (isset($Settings["Surrounding"])) {
                        $this->Data[$NodeID]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"];
                        $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"];
                        $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"];
                    }
                }
            }
        } else {
            if (isset($Settings["R"])) {
                $this->Data[$Nodes]["R"] = $Settings["R"];
            }
            if (isset($Settings["G"])) {
                $this->Data[$Nodes]["G"] = $Settings["G"];
            }
            if (isset($Settings["B"])) {
                $this->Data[$Nodes]["B"] = $Settings["B"];
            }
            if (isset($Settings["Alpha"])) {
                $this->Data[$Nodes]["Alpha"] = $Settings["Alpha"];
            }
            if (isset($Settings["BorderR"])) {
                $this->Data[$Nodes]["BorderR"] = $Settings["BorderR"];
            }
            if (isset($Settings["BorderG"])) {
                $this->Data[$Nodes]["BorderG"] = $Settings["BorderG"];
            }
            if (isset($Settings["BorderB"])) {
                $this->Data[$Nodes]["BorderB"] = $Settings["BorderB"];
            }
            if (isset($Settings["BorderAlpha"])) {
                $this->Data[$Nodes]["BorderAlpha"] = $Settings["BorderAlpha"];
            }
            if (isset($Settings["Surrounding"])) {
                $this->Data[$Nodes]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"];
                $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"];
                $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"];
            }
        }
    }
659168
protected function toNewXmlStructure($nodes)
    {
        $tab = "\t";
        $br = PHP_EOL;
        $xml = '<?xml version="1.0" encoding="UTF-8"?><document type="MelisUserRights" author="MelisTechnology" version="2.0">' . $br;
        unset($nodes['@attributes']);

        $newToolParentNode = 'meliscore_leftmenu';

        foreach ($nodes as $keyNode => $node) {

            if ($newToolParentNode !== $keyNode) {
                $xml .= "<$keyNode>$br";
                if (isset($node['id'])) {
                    if (is_array($node['id'])) {
                        foreach ($node['id'] as $item) {
                            $xml .= "$tab<id>$item</id>$br";
                        }
                    } else {
                        $xml .= "$tab<id>$node[id]</id>$br";
                    }

                }
                $xml .= "</$keyNode>$br";
            } else {
                $xml .= "<$newToolParentNode>$br";
                foreach ($node as $parentKeyNode => $tools) {

                    if (is_array($tools)) {
                        $xml .= "$tab<$parentKeyNode>$br";
                        if (isset($tools['id'])) {
                            $tools = array_map(function ($a) use ($tab, $br) {
                                return "$tab$tab<id>$a</id>";
                            }, $tools['id']);

                            $toolItems = implode($br, $tools) . $br;
                            $xml .= "$toolItems";
                        }

                        $xml .= "$tab</$parentKeyNode>$br";
                    } else {
                        $xml .= "$tab<$parentKeyNode>";
                        $xml .= $tools;
                        $xml .= "</$parentKeyNode>$br";
                    }

                }
                $xml .= "</$newToolParentNode>";

            }
        }
        $xml .= $br . '</document>';

        return $xml;
    }
334575
public static function indentLines($lines, $indent = '  ')
    {
        $lineSeparator = "\n";
        $buffer        = '';
        $line          = strtok($lines, $lineSeparator);
        while ($line) {
            $buffer .= $indent . $line . $lineSeparator;
            $line = strtok($lineSeparator);
        }
        strtok(null, null);

        return $buffer;
    }
809117
public function toXmlLines($indenter = '  ')
    {
        if ($this->isSkip()) {
            $result = null;
        } else {
            if ($indenter) {
                $prefix = $indenter;
                $prefix2 = $indenter . $indenter;
            } else {
                $prefix = '';
                $prefix2 = '';
            }
            $loc = h((string) $this->getUrl());
            $result = [
                "{$prefix}<url>",
                "{$prefix2}<loc>{$loc}</loc>",
            ];
            $lastModifiedAt = $this->getLastModifiedAt();
            if ($lastModifiedAt !== null) {
                $lastModifiedAt = $lastModifiedAt->format(DateTime::ATOM);
                $result[] = "{$prefix2}<lastmod>{$lastModifiedAt}</lastmod>";
            }
            $changeFrequency = $this->getChangeFrequency();
            if ($changeFrequency !== '') {
                $result[] = "{$prefix2}<changefreq>{$changeFrequency}</changefreq>";
            }
            $priority = $this->getPriority();
            if ($priority !== '') {
                $result[] = "{$prefix2}<priority>{$priority}</priority>";
            }
            foreach ($this->getAlternativeLanguages() as $alternativeLanguage) {
                $result = array_merge($result, $alternativeLanguage->toXmlLines($indenter));
            }
            $result[] = "{$prefix}</url>";
        }

        return $result;
    }
1070259
def to_sexp(indent=0)
      indented = "  " * indent
      sexp = "#{indented}(#{fancy_type}"

      children.each do |child|
        if child.is_a?(Node)
          sexp += "\n#{child.to_sexp(indent + 1)}"
        else
          sexp += " #{child.inspect}"
        end
      end

      sexp += ")"

      sexp
    end
292996
private function renderTraits(int $indentLevel = 0): string
    {
        $lines = [];
        foreach ($this->traits as $class => $options) {
            $lines[] = $this->addIndent("use {$class};", $indentLevel);
        }

        return join("\n", $lines);
    }
1241004
protected function buildNestedArray(array $nodes = [], $parentId = 0)
    {
        $branch = [];

        if (empty($nodes)) {
            $nodes = $this->allNodes();
        }

        foreach ($nodes as $node) {
            if ($node[$this->parentColumn] === $parentId) {
                $children = $this->buildNestedArray($nodes, $node[$this->getKeyName()]);

                if ($children) {
                    $node['children'] = $children;
                }

                $branch[] = $node;
            }
        }

        return $branch;
    }
505033
private function addImplicitReturn(array $nodes)
    {
        // If nodes is empty, it can't have a return value.
        if (empty($nodes)) {
            return [new Return_(NoReturnValue::create())];
        }

        $last = \end($nodes);

        // Special case a few types of statements to add an implicit return
        // value (even though they technically don't have any return value)
        // because showing a return value in these instances is useful and not
        // very surprising.
        if ($last instanceof If_) {
            $last->stmts = $this->addImplicitReturn($last->stmts);

            foreach ($last->elseifs as $elseif) {
                $elseif->stmts = $this->addImplicitReturn($elseif->stmts);
            }

            if ($last->else) {
                $last->else->stmts = $this->addImplicitReturn($last->else->stmts);
            }
        } elseif ($last instanceof Switch_) {
            foreach ($last->cases as $case) {
                // only add an implicit return to cases which end in break
                $caseLast = \end($case->stmts);
                if ($caseLast instanceof Break_) {
                    $case->stmts = $this->addImplicitReturn(\array_slice($case->stmts, 0, -1));
                    $case->stmts[] = $caseLast;
                }
            }
        } elseif ($last instanceof Expr && !($last instanceof Exit_)) {
            // @codeCoverageIgnoreStart
            $nodes[\count($nodes) - 1] = new Return_($last, [
                'startLine' => $last->getLine(),
                'endLine'   => $last->getLine(),
            ]);
        // @codeCoverageIgnoreEnd
        } elseif ($last instanceof Expression && !($last->expr instanceof Exit_)) {
            // For PHP Parser 4.x
            $nodes[\count($nodes) - 1] = new Return_($last->expr, [
                'startLine' => $last->getLine(),
                'endLine'   => $last->getLine(),
            ]);
        } elseif ($last instanceof Namespace_) {
            $last->stmts = $this->addImplicitReturn($last->stmts);
        }

        // Return a "no return value" for all non-expression statements, so that
        // PsySH can suppress the `null` that `eval()` returns otherwise.
        //
        // Note that statements special cased above (if/elseif/else, switch)
        // _might_ implicitly return a value before this catch-all return is
        // reached.
        //
        // We're not adding a fallback return after namespace statements,
        // because code outside namespace statements doesn't really work, and
        // there's already an implicit return in the namespace statement anyway.
        if (self::isNonExpressionStmt($last)) {
            $nodes[] = new Return_(NoReturnValue::create());
        }

        return $nodes;
    }