Completed
Push — master ( d07a45...da6ba5 )
by
unknown
02:06
created

src/Adapter/CsvImportAdapterFactory.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * TechDivision\Import\Adapter\CsvImportAdapterFactory
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 TechDivision\Import\Utils\DependencyInjectionKeys;
24
use Symfony\Component\DependencyInjection\ContainerInterface;
25
use TechDivision\Import\Configuration\ImportAdapterAwareConfigurationInterface;
26
27
/**
28
 * Factory for all CSV import 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 CsvImportAdapterFactory implements ImportAdapterFactoryInterface
0 ignored issues
show
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 import adapter for the subject with the passed configuration.
58
     *
59
     * @param \TechDivision\Import\Configuration\ImportAdapterAwareConfigurationInterface $configuration The subject configuration
60
     *
61
     * @return \TechDivision\Import\Adapter\ExportAdapterInterface The import adapter instance
62
     */
63
    public function createImportAdapter(ImportAdapterAwareConfigurationInterface $configuration)
64
    {
65
66
        // load the import adapter configuration
67
        $importAdapterConfiguration = $configuration->getImportAdapter();
68
69
        // load the serializer factory instance
70
        $serializerFactory = $this->container->get($importAdapterConfiguration->getSerializer()->getId());
71
72
        // create the instance and pass the import adapter configuration instance
73
        $importAdapter = $this->container->get(DependencyInjectionKeys::IMPORT_ADAPTER_IMPORT_CSV);
74
        $importAdapter->init($importAdapterConfiguration, $serializerFactory);
75
76
        // return the initialized import adapter instance
77
        return $importAdapter;
78
    }
79
}
80