public function getVariableName() : string
{
if (!$this->node instanceof \ast\Node) {
return (string) $this->node;
}
$node = $this->node;
$parent = $node;
while ($node instanceof \ast\Node && $node->kind != \ast\AST_VAR && $node->kind != \ast\AST_STATIC && $node->kind != \ast\AST_MAGIC_CONST) {
$parent = $node;
$node = array_values($node->children ?? [])[0];
}
if (!$node instanceof \ast\Node) {
return (string) $node;
}
if (empty($node->children['name'])) {
return '';
}
if ($node->children['name'] instanceof \ast\Node) {
return '';
}
return (string) $node->children['name'];
}