Created
April 26, 2018 19:33
-
-
Save Ocramius/287a632af65fce13493fc9c8e5a53e94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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