Skip to content

Commit 8b5c9b8

Browse files
seizan8mamazu
authored andcommitted
refactor: optimized factories to be extended
1 parent 75a5f7a commit 8b5c9b8

File tree

4 files changed

+22
-35
lines changed

4 files changed

+22
-35
lines changed

src/Factory/CustomerOptionFactory.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,14 @@
2525

2626
class CustomerOptionFactory implements CustomerOptionFactoryInterface
2727
{
28-
/**
29-
* @var RepositoryInterface
30-
*/
31-
private $customerOptionGroupRepository;
28+
/** @var RepositoryInterface */
29+
protected $customerOptionGroupRepository;
3230

33-
/**
34-
* @var \Faker\Generator
35-
*/
36-
private $faker;
37-
/**
38-
* @var CustomerOptionValueFactoryInterface
39-
*/
40-
private $customerOptionValueFactory;
31+
/** @var \Faker\Generator */
32+
protected $faker;
33+
34+
/** @var CustomerOptionValueFactoryInterface */
35+
protected $customerOptionValueFactory;
4136

4237
public function __construct(
4338
CustomerOptionGroupRepositoryInterface $customerOptionGroupRepository,
@@ -86,7 +81,7 @@ public function createFromConfig(array $configuration): CustomerOptionInterface
8681
{
8782
$this->validateConfiguration($configuration);
8883

89-
$customerOption = new CustomerOption();
84+
$customerOption = $this->createNew();
9085
$customerOption->setCode($configuration['code']);
9186

9287
foreach ($configuration['translations'] as $locale => $name) {

src/Factory/CustomerOptionGroupFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
class CustomerOptionGroupFactory implements CustomerOptionGroupFactoryInterface
3333
{
3434
/** @var CustomerOptionRepositoryInterface */
35-
private $customerOptionRepository;
35+
protected $customerOptionRepository;
3636

3737
/** @var ProductRepositoryInterface */
38-
private $productRepository;
38+
protected $productRepository;
3939

4040
/** @var \Faker\Generator */
41-
private $faker;
41+
protected $faker;
4242

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

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

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

src/Factory/CustomerOptionValueFactory.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@
2020

2121
class CustomerOptionValueFactory implements CustomerOptionValueFactoryInterface
2222
{
23-
/**
24-
* @var CustomerOptionValuePriceFactoryInterface
25-
*/
26-
private $valuePriceFactory;
23+
/** @var CustomerOptionValuePriceFactoryInterface */
24+
protected $valuePriceFactory;
2725

28-
/**
29-
* @var Generator
30-
*/
31-
private $faker;
26+
/** @var Generator */
27+
protected $faker;
3228

3329
public function __construct(CustomerOptionValuePriceFactoryInterface $valuePriceFactory)
3430
{
@@ -60,7 +56,7 @@ public function validateConfiguration(array $configuration): void
6056
/** {@inheritdoc} */
6157
public function createFromConfig(array $configuration): CustomerOptionValueInterface
6258
{
63-
$value = new CustomerOptionValue();
59+
$value = $this->createNew();
6460
$value->setCode($configuration['code']);
6561

6662
foreach ($configuration['translations'] as $locale => $name) {

src/Factory/CustomerOptionValuePriceFactory.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323

2424
class CustomerOptionValuePriceFactory implements CustomerOptionValuePriceFactoryInterface
2525
{
26-
/**
27-
* @var ChannelRepositoryInterface
28-
*/
29-
private $channelRepository;
26+
/** @var ChannelRepositoryInterface */
27+
protected $channelRepository;
3028

31-
/**
32-
* @var Generator
33-
*/
34-
private $faker;
29+
/** @var Generator */
30+
protected $faker;
3531

3632
public function __construct(ChannelRepositoryInterface $channelRepository)
3733
{
@@ -58,7 +54,7 @@ public function createFromConfig(array $configuration): CustomerOptionValuePrice
5854
{
5955
$this->validateConfiguration($configuration);
6056

61-
$price = new CustomerOptionValuePrice();
57+
$price = $this->createNew();
6258

6359
switch ($configuration['type']) {
6460
case 'fixed':

0 commit comments

Comments
 (0)