From 8b5c9b89b2b782581a6fd5aefe5bb425d67438fc Mon Sep 17 00:00:00 2001 From: Basil Baumgartner Date: Fri, 21 May 2021 19:01:34 +0200 Subject: [PATCH] refactor: optimized factories to be extended --- src/Factory/CustomerOptionFactory.php | 21 +++++++------------ src/Factory/CustomerOptionGroupFactory.php | 8 +++---- src/Factory/CustomerOptionValueFactory.php | 14 +++++-------- .../CustomerOptionValuePriceFactory.php | 14 +++++-------- 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/Factory/CustomerOptionFactory.php b/src/Factory/CustomerOptionFactory.php index f0bdfd8f..a3063403 100644 --- a/src/Factory/CustomerOptionFactory.php +++ b/src/Factory/CustomerOptionFactory.php @@ -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, @@ -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) { diff --git a/src/Factory/CustomerOptionGroupFactory.php b/src/Factory/CustomerOptionGroupFactory.php index 90c67256..b37d19bc 100644 --- a/src/Factory/CustomerOptionGroupFactory.php +++ b/src/Factory/CustomerOptionGroupFactory.php @@ -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, @@ -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']); diff --git a/src/Factory/CustomerOptionValueFactory.php b/src/Factory/CustomerOptionValueFactory.php index 3a44a946..09633e49 100644 --- a/src/Factory/CustomerOptionValueFactory.php +++ b/src/Factory/CustomerOptionValueFactory.php @@ -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) { @@ -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) { diff --git a/src/Factory/CustomerOptionValuePriceFactory.php b/src/Factory/CustomerOptionValuePriceFactory.php index e53cd5db..e4dfab77 100644 --- a/src/Factory/CustomerOptionValuePriceFactory.php +++ b/src/Factory/CustomerOptionValuePriceFactory.php @@ -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) { @@ -58,7 +54,7 @@ public function createFromConfig(array $configuration): CustomerOptionValuePrice { $this->validateConfiguration($configuration); - $price = new CustomerOptionValuePrice(); + $price = $this->createNew(); switch ($configuration['type']) { case 'fixed':