Skip to content

Commit

Permalink
refactor: optimized factories to be extended
Browse files Browse the repository at this point in the history
  • Loading branch information
seizan8 authored and mamazu committed May 31, 2021
1 parent 75a5f7a commit 8b5c9b8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
21 changes: 8 additions & 13 deletions src/Factory/CustomerOptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,14 @@

class CustomerOptionFactory implements CustomerOptionFactoryInterface
{
/**
* @var RepositoryInterface
*/
private $customerOptionGroupRepository;
/** @var RepositoryInterface */
protected $customerOptionGroupRepository;

/**
* @var \Faker\Generator
*/
private $faker;
/**
* @var CustomerOptionValueFactoryInterface
*/
private $customerOptionValueFactory;
/** @var \Faker\Generator */
protected $faker;

/** @var CustomerOptionValueFactoryInterface */
protected $customerOptionValueFactory;

public function __construct(
CustomerOptionGroupRepositoryInterface $customerOptionGroupRepository,
Expand Down Expand Up @@ -86,7 +81,7 @@ public function createFromConfig(array $configuration): CustomerOptionInterface
{
$this->validateConfiguration($configuration);

$customerOption = new CustomerOption();
$customerOption = $this->createNew();
$customerOption->setCode($configuration['code']);

foreach ($configuration['translations'] as $locale => $name) {
Expand Down
8 changes: 4 additions & 4 deletions src/Factory/CustomerOptionGroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
class CustomerOptionGroupFactory implements CustomerOptionGroupFactoryInterface
{
/** @var CustomerOptionRepositoryInterface */
private $customerOptionRepository;
protected $customerOptionRepository;

/** @var ProductRepositoryInterface */
private $productRepository;
protected $productRepository;

/** @var \Faker\Generator */
private $faker;
protected $faker;

public function __construct(
CustomerOptionRepositoryInterface $customerOptionRepository,
Expand Down Expand Up @@ -95,7 +95,7 @@ public function createFromConfig(array $options): CustomerOptionGroupInterface
$options = array_merge($this->getOptionsSkeleton(), $options);
Assert::minCount($options['translations'], 1);

$customerOptionGroup = new CustomerOptionGroup();
$customerOptionGroup = $this->createNew();

$customerOptionGroup->setCode($options['code']);

Expand Down
14 changes: 5 additions & 9 deletions src/Factory/CustomerOptionValueFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@

class CustomerOptionValueFactory implements CustomerOptionValueFactoryInterface
{
/**
* @var CustomerOptionValuePriceFactoryInterface
*/
private $valuePriceFactory;
/** @var CustomerOptionValuePriceFactoryInterface */
protected $valuePriceFactory;

/**
* @var Generator
*/
private $faker;
/** @var Generator */
protected $faker;

public function __construct(CustomerOptionValuePriceFactoryInterface $valuePriceFactory)
{
Expand Down Expand Up @@ -60,7 +56,7 @@ public function validateConfiguration(array $configuration): void
/** {@inheritdoc} */
public function createFromConfig(array $configuration): CustomerOptionValueInterface
{
$value = new CustomerOptionValue();
$value = $this->createNew();
$value->setCode($configuration['code']);

foreach ($configuration['translations'] as $locale => $name) {
Expand Down
14 changes: 5 additions & 9 deletions src/Factory/CustomerOptionValuePriceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@

class CustomerOptionValuePriceFactory implements CustomerOptionValuePriceFactoryInterface
{
/**
* @var ChannelRepositoryInterface
*/
private $channelRepository;
/** @var ChannelRepositoryInterface */
protected $channelRepository;

/**
* @var Generator
*/
private $faker;
/** @var Generator */
protected $faker;

public function __construct(ChannelRepositoryInterface $channelRepository)
{
Expand All @@ -58,7 +54,7 @@ public function createFromConfig(array $configuration): CustomerOptionValuePrice
{
$this->validateConfiguration($configuration);

$price = new CustomerOptionValuePrice();
$price = $this->createNew();

switch ($configuration['type']) {
case 'fixed':
Expand Down

0 comments on commit 8b5c9b8

Please sign in to comment.