private function extract($file, ValidationExtractor $extractor = null)
 {
     if (!is_file($file = __DIR__ . '/Fixture/' . $file)) {
         throw new RuntimeException(sprintf('The file "%s" does not exist.', $file));
     }
     $file = new \SplFileInfo($file);
     //use correct factory class depending on whether using Symfony 2 or 3
     if (class_exists('Symfony\\Component\\Validator\\Mapping\\Factory\\LazyLoadingMetadataFactory')) {
         $metadataFactoryClass = 'Symfony\\Component\\Validator\\Mapping\\Factory\\LazyLoadingMetadataFactory';
     } else {
         $metadataFactoryClass = 'Symfony\\Component\\Validator\\Mapping\\ClassMetadataFactory';
     }
     if (null === $extractor) {
         $factory = new $metadataFactoryClass(new AnnotationLoader(new AnnotationReader()));
         $extractor = new ValidationExtractor($factory);
     }
     $lexer = new Lexer();
     if (class_exists('PhpParser\\ParserFactory')) {
         $factory = new ParserFactory();
         $parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
     } else {
         $parser = new Parser($lexer);
     }
     $ast = $parser->parse(file_get_contents($file));
     $catalogue = new MessageCatalogue();
     $extractor->visitPhpFile($file, $catalogue, $ast);
     return $catalogue;
 }
 private function extract($file, ValidationExtractor $extractor = null)
 {
     if (!is_file($file = __DIR__ . '/Fixture/' . $file)) {
         throw new RuntimeException(sprintf('The file "%s" does not exist.', $file));
     }
     $file = new \SplFileInfo($file);
     if (null === $extractor) {
         $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
         $extractor = new ValidationExtractor($factory);
     }
     $lexer = new \PHPParser_Lexer();
     $parser = new \PHPParser_Parser($lexer);
     $ast = $parser->parse(file_get_contents($file));
     $catalogue = new MessageCatalogue();
     $extractor->visitPhpFile($file, $catalogue, $ast);
     return $catalogue;
 }