/** * @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; }
/** * @param FilesCollection $files * * @return ParseErrorsCollection */ protected function parse(FilesCollection $files) { // Skip ignored patterns: $configuration = $this->getConfiguration(); foreach ($configuration['ignore_patterns'] as $pattern) { $files = $files->notPath($pattern); } // Parse every file: $parseErrors = new ParseErrorsCollection(); foreach ($files as $file) { foreach ($this->parser->parse($file) as $error) { $parseErrors->add($error); } } return $parseErrors; }