/**
  * @param FamilyInterface $family
  *
  * @return string[]
  */
 protected function getMissingChannelCodes(FamilyInterface $family)
 {
     $requirements = $family->getAttributeRequirements();
     $identifierCode = $this->attributeRepository->getIdentifierCode();
     $currentChannelCodes = [];
     foreach ($requirements as $requirement) {
         if ($requirement->getAttributeCode() === $identifierCode) {
             $currentChannelCodes[] = $requirement->getChannelCode();
         }
     }
     $expectedChannelCodes = $this->channelRepository->getChannelCodes();
     $missingChannelCodes = array_diff($expectedChannelCodes, $currentChannelCodes);
     return $missingChannelCodes;
 }
 /**
  * @return string
  */
 protected function getIdentifierCode()
 {
     if (null === $this->identifierCode) {
         $this->identifierCode = $this->attributeRepository->getIdentifierCode();
     }
     return $this->identifierCode;
 }
 /**
  * {@inheritdoc}
  */
 public function generate(array $config, $outputDir, ProgressHelper $progress, array $options = null)
 {
     $this->tmpFile = tempnam(sys_get_temp_dir(), 'data-gene');
     if (!empty($config['filename'])) {
         $this->outputFile = $outputDir . '/' . trim($config['filename']);
     } else {
         $this->outputFile = $outputDir . '/' . self::DEFAULT_FILENAME;
     }
     $count = (int) $config['count'];
     $nbAttrBase = (int) $config['filled_attributes_count'];
     $nbAttrDeviation = (int) $config['filled_attributes_standard_deviation'];
     $startIndex = (int) $config['start_index'];
     $categoriesCount = (int) $config['categories_count'];
     $mandatoryAttributes = $config['mandatory_attributes'];
     if (!is_array($mandatoryAttributes)) {
         $mandatoryAttributes = [];
     }
     $delimiter = $config['delimiter'];
     $this->delimiter = $delimiter != null ? $delimiter : self::DEFAULT_DELIMITER;
     if (isset($config['force_values'])) {
         $this->forcedValues = $config['force_values'];
     } else {
         $this->forcedValues = [];
     }
     $this->identifierCode = $this->attributeRepository->getIdentifierCode();
     $this->faker = Faker\Factory::create();
     for ($i = $startIndex; $i < $startIndex + $count; $i++) {
         $product = [];
         $product[$this->identifierCode] = self::IDENTIFIER_PREFIX . $i;
         $family = $this->getRandomFamily($this->faker);
         $product['family'] = $family->getCode();
         if ($nbAttrBase > 0) {
             if ($nbAttrDeviation > 0) {
                 $nbAttr = $this->faker->numberBetween($nbAttrBase - round($nbAttrDeviation / 2), $nbAttrBase + round($nbAttrDeviation / 2));
             } else {
                 $nbAttr = $nbAttrBase;
             }
         }
         $familyAttrCount = count($this->getAttributesFromFamily($family));
         if (!isset($nbAttr) || $nbAttr > $familyAttrCount) {
             $nbAttr = $familyAttrCount;
         }
         $attributes = $this->getRandomAttributesFromFamily($family, $nbAttr);
         foreach ($attributes as $attribute) {
             $valueData = $this->generateValue($attribute);
             $product = array_merge($product, $valueData);
         }
         foreach ($mandatoryAttributes as $mandatoryAttribute) {
             if (isset($this->attributesByFamily[$family->getCode()][$mandatoryAttribute])) {
                 $attribute = $this->attributesByFamily[$family->getCode()][$mandatoryAttribute];
                 $valueData = $this->generateValue($attribute);
                 $product = array_merge($product, $valueData);
             }
         }
         $categories = $this->getRandomCategoryCodes($categoriesCount);
         $product[self::CATEGORY_FIELD] = implode(',', $categories);
         $this->bufferizeProduct($product);
         $progress->advance();
     }
     $this->writeCsvFile();
     unlink($this->tmpFile);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function getIdentifierProperties()
 {
     return array($this->attributeRepository->getIdentifierCode());
 }
 /**
  * @param string $code
  *
  * @return bool
  */
 protected function isAttribute($code)
 {
     return null !== $this->attributeRepository->getIdentifierCode($code);
 }
 /**
  * @param ProductRepositoryInterface   $productRepository
  * @param AttributeRepositoryInterface $attributeRepository
  */
 public function __construct(ProductRepositoryInterface $productRepository, AttributeRepositoryInterface $attributeRepository)
 {
     $this->attributeRepository = $attributeRepository;
     $this->identifierCode = $attributeRepository->getIdentifierCode();
 }