parserFactory = $parserFactory; $this->traverserFactory = $traverserFactory; $this->filesystem = $filesystem; } public function setParserOptions(array $options): void { $this->parserOptions = $options; } public function parse(SplFileInfo $file): ParseErrorsCollection { $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; } public function isInstalled(): bool { return interface_exists(Parser::class); } }