function NodeDumper::dumpRecursive
Parameters
mixed $node :
1 call to NodeDumper::dumpRecursive()
- NodeDumper::dump in vendor/
nikic/ php-parser/ lib/ PhpParser/ NodeDumper.php - Dumps a node or array.
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ NodeDumper.php, line 69
Class
Namespace
PhpParserCode
protected function dumpRecursive($node, bool $indent = true) : void {
if ($indent) {
$this->nl .= " ";
}
if ($node instanceof Node) {
$this->res .= $node->getType();
if ($this->dumpPositions && null !== ($p = $this->dumpPosition($node))) {
$this->res .= $p;
}
$this->res .= '(';
foreach ($node->getSubNodeNames() as $key) {
$this->res .= "{$this->nl} " . $key . ': ';
$value = $node->{$key};
if (\is_int($value)) {
if ('flags' === $key || 'newModifier' === $key) {
$this->res .= $this->dumpFlags($value);
continue;
}
if ('type' === $key && $node instanceof Include_) {
$this->res .= $this->dumpIncludeType($value);
continue;
}
if ('type' === $key && ($node instanceof Use_ || $node instanceof UseItem || $node instanceof GroupUse)) {
$this->res .= $this->dumpUseType($value);
continue;
}
}
$this->dumpRecursive($value);
}
if ($this->dumpComments && ($comments = $node->getComments())) {
$this->res .= "{$this->nl} comments: ";
$this->dumpRecursive($comments);
}
if ($this->dumpOtherAttributes) {
foreach ($node->getAttributes() as $key => $value) {
if (isset(self::IGNORE_ATTRIBUTES[$key])) {
continue;
}
$this->res .= "{$this->nl} {$key}: ";
if (\is_int($value)) {
if ('kind' === $key) {
if ($node instanceof Int_) {
$this->res .= $this->dumpIntKind($value);
continue;
}
if ($node instanceof String_ || $node instanceof InterpolatedString) {
$this->res .= $this->dumpStringKind($value);
continue;
}
if ($node instanceof Array_) {
$this->res .= $this->dumpArrayKind($value);
continue;
}
if ($node instanceof List_) {
$this->res .= $this->dumpListKind($value);
continue;
}
}
}
$this->dumpRecursive($value);
}
}
$this->res .= "{$this->nl})";
}
elseif (\is_array($node)) {
$this->res .= 'array(';
foreach ($node as $key => $value) {
$this->res .= "{$this->nl} " . $key . ': ';
$this->dumpRecursive($value);
}
$this->res .= "{$this->nl})";
}
elseif ($node instanceof Comment) {
$this->res .= \str_replace("\n", $this->nl, $node->getReformattedText());
}
elseif (\is_string($node)) {
$this->res .= \str_replace("\n", $this->nl, (string) $node);
}
elseif (\is_int($node) || \is_float($node)) {
$this->res .= $node;
}
elseif (null === $node) {
$this->res .= 'null';
}
elseif (false === $node) {
$this->res .= 'false';
}
elseif (true === $node) {
$this->res .= 'true';
}
else {
throw new \InvalidArgumentException('Can only dump nodes and arrays.');
}
if ($indent) {
$this->nl = \substr($this->nl, 0, -4);
}
}