Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
declare(strict_types=1);
namespace Roave\BetterReflection\SourceLocator\Ast\Parser;
use PhpParser\ErrorHandler;
use PhpParser\NodeTraverser;
use PhpParser\NodeTraverserInterface;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\Parser;
use function array_key_exists;
use function hash;
use function strlen;
/**
* @internal
*/
final class NameResolvingParser implements Parser
{
/** @var NodeTraverserInterface */
private $traverser;
/** @var Parser */
private $wrappedParser;
public function __construct(Parser $wrappedParser)
{
$this->wrappedParser = $wrappedParser;
$this->traverser = new NodeTraverser();
$this->traverser->addVisitor(new NameResolver());
}
/**
* {@inheritDoc}
*
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
*/
public function parse($code, ?ErrorHandler $errorHandler = null) : ?array
{
$ast = $this->wrappedParser->parse($code, $errorHandler);
$this->traverser->traverse($ast);
return $ast;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment