1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Serializers\ProductCategoryCsvSerializerFactory.php |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2021 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Serializers; |
22
|
|
|
|
23
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
24
|
|
|
use TechDivision\Import\Utils\DependencyInjectionKeys; |
25
|
|
|
use TechDivision\Import\Serializer\SerializerFactoryInterface; |
26
|
|
|
use TechDivision\Import\Serializer\Configuration\SerializerConfigurationInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The factory implementation for product category CSV value serializer instances. |
30
|
|
|
* |
31
|
|
|
* @author Tim Wagner <[email protected]> |
32
|
|
|
* @copyright 2021 TechDivision GmbH <[email protected]> |
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
34
|
|
|
* @link https://github.com/techdivision/import |
35
|
|
|
* @link http://www.techdivision.com |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
class ProductCategoryCsvSerializerFactory implements SerializerFactoryInterface |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The DI container instance. |
42
|
|
|
* |
43
|
|
|
* @var \Symfony\Component\DependencyInjection\ContainerInterface |
44
|
|
|
*/ |
45
|
|
|
protected $container; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Initialize the factory with the DI container instance. |
49
|
|
|
* |
50
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container The DI container instance |
51
|
|
|
*/ |
52
|
|
|
public function __construct(ContainerInterface $container) |
53
|
|
|
{ |
54
|
|
|
$this->container = $container; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Creates and returns the serializer instance. |
59
|
|
|
* |
60
|
|
|
* @param \TechDivision\Import\Serializer\Configuration\SerializerConfigurationInterface $serializerConfiguration The serializer configuration |
61
|
|
|
* |
62
|
|
|
* @return \TechDivision\Import\Serializer\ConfigurationAwareSerializerInterface The serializer instance |
63
|
|
|
*/ |
64
|
|
|
public function createSerializer(SerializerConfigurationInterface $serializerConfiguration) |
65
|
|
|
{ |
66
|
|
|
|
67
|
|
|
// load the serializer instance from the container and pass the configuration |
68
|
|
|
/** @var \TechDivision\Import\Serializer\SerializerInterface $serializer */ |
69
|
|
|
$serializer = $this->container->get(DependencyInjectionKeys::IMPORT_SERIALIZER_CSV_PRODUCT_CATEGORY); |
70
|
|
|
$serializer->init($serializerConfiguration); |
71
|
|
|
|
72
|
|
|
// return the serializer instance |
73
|
|
|
return $serializer; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.