Phan\Debug::nodeToString PHP Method

nodeToString() public static method

public static nodeToString ( string | ast\Node | null $node, $name = null, integer $indent ) : string
$node string | ast\Node | null An AST node
$indent integer The indentation level for the string
return string A string representation of an AST node
    public static function nodeToString($node, $name = null, int $indent = 0) : string
    {
        $string = str_repeat("\t", $indent);
        if ($name !== null) {
            $string .= "{$name} => ";
        }
        if (is_string($node)) {
            return $string . $node . "\n";
        }
        if (!$node) {
            return $string . 'null' . "\n";
        }
        if (!is_object($node)) {
            return $string . $node . "\n";
        }
        $string .= \ast\get_kind_name($node->kind);
        $string .= ' [' . self::astFlagDescription($node->flags ?? 0) . ']';
        if (isset($node->lineno)) {
            $string .= ' #' . $node->lineno;
        }
        if ($node instanceof Decl) {
            if (isset($node->endLineno)) {
                $string .= ':' . $node->endLineno;
            }
        }
        if (isset($node->name)) {
            $string .= ' name:' . $node->name;
        }
        $string .= "\n";
        foreach ($node->children ?? [] as $name => $child_node) {
            $string .= self::nodeToString($child_node, $name, $indent + 1);
        }
        return $string;
    }