/**
  * @param FeedTypeInterface $type
  * @param OutputInterface   $output
  *
  * @return int
  */
 protected function validate(FeedTypeInterface $type, OutputInterface $output)
 {
     $file = $this->exporter->getFeedFilename($type);
     if (!file_exists($file)) {
         throw new FileNotFoundException(sprintf('<error>Feed "%s" has not yet been exported</error>', $type->getName()));
     }
     $options = LIBXML_NOENT | LIBXML_COMPACT | LIBXML_PARSEHUGE | LIBXML_NOERROR | LIBXML_NOWARNING;
     $this->reader = new \XMLReader($options);
     $this->reader->open($file);
     $this->reader->setParserProperty(\XMLReader::SUBST_ENTITIES, true);
     //        foreach ($type->getNamespaces() as $name => $location) {
     //            $this->reader->setSchema($location);
     //        }
     libxml_clear_errors();
     libxml_use_internal_errors(true);
     libxml_disable_entity_loader(true);
     $progress = new ProgressBar($output);
     $progress->start();
     // go through the whole thing
     while ($this->reader->read()) {
         if ($this->reader->nodeType === \XMLReader::ELEMENT && $this->reader->name === $type->getItemNode()) {
             $progress->advance();
             $this->currentItem = $this->reader->readOuterXml();
         }
         if ($error = libxml_get_last_error()) {
             throw new \RuntimeException(sprintf('[%s %s] %s (in %s - line %d, column %d)', LIBXML_ERR_WARNING === $error->level ? 'WARNING' : 'ERROR', $error->code, trim($error->message), $error->file ? $error->file : 'n/a', $error->line, $error->column));
         }
     }
     $progress->finish();
 }
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $type = $this->exporter->getType($input->getArgument('type'));
     $file = $this->exporter->getFeedFilename($type);
     if (!file_exists($file)) {
         $output->writeln(sprintf('<error>Feed "%s" has not yet been exported</error>', $type->getName()));
         return 1;
     }
     $evaluationMethod = $input->getOption('evaluate');
     $evaluationExpression = $input->getOption('expression');
     if (!$evaluationMethod && $evaluationExpression) {
         $evaluationMethod = self::EVALUATE_EXPRESSION;
     }
     if (!$evaluationMethod) {
         $evaluationMethod = self::EVALUATE_COUNT;
     }
     list($results, $total) = $this->inspect($output, new \SplFileInfo($file), $input->getOption('filter'));
     switch ($evaluationMethod) {
         case self::EVALUATE_COUNT:
             if ($evaluationExpression) {
                 throw new \InvalidArgumentException('You cannot use an expression when using count evaluation');
             }
             $this->evaluateCount($output, $results, $total);
             break;
         case self::EVALUATE_EXPRESSION:
             $this->evaluateResult($output, $evaluationExpression, $results, $total);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Invalid evaluation method: %s', $evaluationMethod));
     }
     return 0;
 }