Completed
Push — 8.x ( 824af6 )
by Tim
09:11
created

CsvExportAdapterFactory::createExportAdapter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 16
loc 16
c 0
b 0
f 0
ccs 0
cts 8
cp 0
rs 9.7333
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Adapter\CsvExportAdapterFactory
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 2016 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\Adapter;
22
23
use Symfony\Component\DependencyInjection\ContainerInterface;
24
use TechDivision\Import\Configuration\SubjectConfigurationInterface;
25
use TechDivision\Import\Utils\DependencyInjectionKeys;
26
27
/**
28
 * Factory for all CSV export adapter implementations.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2016 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/techdivision/import
34
 * @link      http://www.techdivision.com
35
 */
36 View Code Duplication
class CsvExportAdapterFactory implements ExportAdapterFactoryInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
37
{
38
39
    /**
40
     * The DI container instance.
41
     *
42
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
43
     */
44
    protected $container;
45
46
    /**
47
     * Initialize the factory with the DI container instance.
48
     *
49
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container The DI container instance
50
     */
51
    public function __construct(ContainerInterface $container)
52
    {
53
        $this->container = $container;
54
    }
55
56
    /**
57
     * Creates and returns the export adapter for the subject with the passed configuration.
58
     *
59
     * @param \TechDivision\Import\Configuration\SubjectConfigurationInterface $subjectConfiguration The subject configuration
60
     *
61
     * @return \TechDivision\Import\Adapter\ExportAdapterInterface The export adapter instance
62
     */
63
    public function createExportAdapter(SubjectConfigurationInterface $subjectConfiguration)
64
    {
65
66
        // load the export adapter configuration
67
        $exportAdapterConfiguration = $subjectConfiguration->getExportAdapter();
68
69
        // load the serializer factory instance
70
        $serializerFactory = $this->container->get($exportAdapterConfiguration->getSerializer()->getId());
71
72
        // create the instance and pass the export adapter configuration instance
73
        $exportAdapter = $this->container->get(DependencyInjectionKeys::IMPORT_ADAPTER_EXPORT_CSV);
74
        $exportAdapter->init($exportAdapterConfiguration, $serializerFactory);
75
76
        // return the initialized export adapter instance
77
        return $exportAdapter;
78
    }
79
}
80