function Node::__toString
Same name in this branch
- 11.1.x vendor/phpstan/phpdoc-parser/src/Ast/Node.php \PHPStan\PhpDocParser\Ast\Node::__toString()
File
-
vendor/
twig/ twig/ src/ Node/ Node.php, line 68
Class
- Node
- Represents a node in the AST.
Namespace
Twig\NodeCode
public function __toString() {
$repr = static::class;
if ($this->tag) {
$repr .= \sprintf("\n tag: %s", $this->tag);
}
$attributes = [];
foreach ($this->attributes as $name => $value) {
if (\is_callable($value)) {
$v = '\\Closure';
}
elseif ($value instanceof \Stringable) {
$v = (string) $value;
}
else {
$v = str_replace("\n", '', var_export($value, true));
}
$attributes[] = \sprintf('%s: %s', $name, $v);
}
if ($attributes) {
$repr .= \sprintf("\n attributes:\n %s", implode("\n ", $attributes));
}
if (\count($this->nodes)) {
$repr .= "\n nodes:";
foreach ($this->nodes as $name => $node) {
$len = \strlen($name) + 6;
$noderepr = [];
foreach (explode("\n", (string) $node) as $line) {
$noderepr[] = str_repeat(' ', $len) . $line;
}
$repr .= \sprintf("\n %s: %s", $name, ltrim(implode("\n", $noderepr)));
}
}
return $repr;
}