public function createForTaskContext(array $parserOptions, ParserContext $context) { $this->configurator->registerOptions($parserOptions); $this->configurator->registerContext($context); $traverser = new NodeTraverser(); $this->configurator->configure($traverser); return $traverser; }
/** * @param SplFileInfo $file * * @return ParseErrorsCollection */ public function parse(SplFileInfo $file) { $errors = new ParseErrorsCollection(); $context = new ParserContext($file, $errors); $parser = $this->parserFactory->createFromOptions($this->parserOptions); $traverser = $this->traverserFactory->createForTaskContext($this->parserOptions, $context); try { $code = $this->filesystem->readFromFileInfo($file); $stmts = $parser->parse($code); $traverser->traverse($stmts); } catch (Error $e) { $errors->add(PhpParserError::fromParseException($e, $file->getRealPath())); } return $errors; }