function JsonDecoder::decodeNode
1 call to JsonDecoder::decodeNode()
- JsonDecoder::decodeRecursive in vendor/
nikic/ php-parser/ lib/ PhpParser/ JsonDecoder.php
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ JsonDecoder.php, line 44
Class
Namespace
PhpParserCode
private function decodeNode(array $value) : Node {
$nodeType = $value['nodeType'];
if (!\is_string($nodeType)) {
throw new \RuntimeException('Node type must be a string');
}
$reflectionClass = $this->reflectionClassFromNodeType($nodeType);
$node = $reflectionClass->newInstanceWithoutConstructor();
if (isset($value['attributes'])) {
if (!\is_array($value['attributes'])) {
throw new \RuntimeException('Attributes must be an array');
}
$node->setAttributes($this->decodeArray($value['attributes']));
}
foreach ($value as $name => $subNode) {
if ($name === 'nodeType' || $name === 'attributes') {
continue;
}
$node->{$name} = $this->decodeRecursive($subNode);
}
return $node;
}