/** * Resolve unexisting names by searching specified namespaces * * @param Node $node * @return \PhpParser\Node\Name|null * @throws RuntimeException If name can not be resolved */ public function leaveNode(Node $node) { if ($node instanceof FullyQualified) { $name = new Name((string) $node); $whitelisted = $this->isWhitelisted($name); if (!$name->isDefined(!$whitelisted)) { /** @var Name $namespace */ foreach ($this->search as $namespace) { $newName = new Name("{$namespace}\\{$node->getLast()}"); if ($newName->isDefined()) { return $newName->createNode(); } } if (!$whitelisted) { throw new RuntimeException("Unable to resolve class <{$node}>."); } } } }