/**
  * {@inheritdoc}
  */
 public function doExecute(StepExecution $stepExecution)
 {
     $itemsToWrite = array();
     $writeCount = 0;
     $this->initializeStepElements($stepExecution);
     $stopExecution = false;
     while (!$stopExecution) {
         try {
             $readItem = $this->reader->read();
             if (null === $readItem) {
                 $stopExecution = true;
                 continue;
             }
         } catch (InvalidItemException $e) {
             $this->handleStepExecutionWarning($this->stepExecution, $this->reader, $e);
             continue;
         }
         $processedItem = $this->process($readItem);
         if (null !== $processedItem) {
             $itemsToWrite[] = $processedItem;
             $writeCount++;
             if (0 === $writeCount % $this->batchSize) {
                 $this->write($itemsToWrite);
                 $itemsToWrite = array();
                 $this->getJobRepository()->updateStepExecution($stepExecution);
             }
         }
     }
     if (count($itemsToWrite) > 0) {
         $this->write($itemsToWrite);
     }
     $this->flushStepElements();
 }
 /**
  * {@inheritdoc}
  */
 public function analyze(ItemReaderInterface $reader)
 {
     $stats = ["columns_count" => 0, "products" => ["count" => 0, "values_count" => 0, "values_per_product" => []]];
     $lineNumber = 1;
     while ($valuesData = $reader->read()) {
         if (0 === $stats['columns_count']) {
             $stats['columns_count'] = count($valuesData);
         }
         $valuesCount = $this->countValues($valuesData);
         $stats['products']['count']++;
         $stats['products']['values_count'] += $valuesCount;
         $stats['products']['values_per_product'] = $this->computeValuesStats($valuesCount, $stats['products']['values_per_product'], $lineNumber);
         $lineNumber++;
     }
     if ($stats['products']['count'] > 0) {
         $stats['products']['values_per_product']['average'] = round($stats['products']['values_count'] / $stats['products']['count']);
     }
     return $stats;
 }
 function it_analyzes_empty_product_data(ItemReaderInterface $reader)
 {
     $reader->read()->willReturn(null);
     $this->analyze($reader)->shouldBeLike(["columns_count" => 0, "products" => ["count" => 0, "values_count" => 0, "values_per_product" => []]]);
 }
 /**
  * {@inheritdoc}
  */
 public function flush()
 {
     if ($this->reader instanceof FlushableInterface) {
         $this->reader->flush();
     }
 }