Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Created April 26, 2018 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ocramius/287a632af65fce13493fc9c8e5a53e94 to your computer and use it in GitHub Desktop.
Save Ocramius/287a632af65fce13493fc9c8e5a53e94 to your computer and use it in GitHub Desktop.
<?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