Completed
Pull Request — master (#13)
by Tim
05:57
created

ProductBundleProcessorFactory   B

Complexity

Total Complexity 2

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 17

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 17
dl 0
loc 115
ccs 0
cts 75
cp 0
rs 7.8571

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getProcessorType() 0 4 1
B factory() 0 93 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Cli\Services\ProductBundleProcessorFactory
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-cli-simple
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Cli\Services;
22
23
use TechDivision\Import\Configuration\SubjectInterface;
24
use TechDivision\Import\Product\Bundle\Actions\ProductBundleOptionAction;
25
use TechDivision\Import\Product\Bundle\Actions\ProductBundleOptionValueAction;
26
use TechDivision\Import\Product\Bundle\Actions\ProductBundleSelectionAction;
27
use TechDivision\Import\Product\Bundle\Actions\ProductBundleSelectionPriceAction;
28
use TechDivision\Import\Product\Bundle\Repositories\BundleOptionRepository;
29
use TechDivision\Import\Product\Bundle\Repositories\BundleOptionValueRepository;
30
use TechDivision\Import\Product\Bundle\Repositories\BundleSelectionRepository;
31
use TechDivision\Import\Product\Bundle\Repositories\BundleSelectionPriceRepository;
32
use TechDivision\Import\Product\Bundle\Actions\Processors\ProductBundleOptionCreateProcessor;
33
use TechDivision\Import\Product\Bundle\Actions\Processors\ProductBundleOptionUpdateProcessor;
34
use TechDivision\Import\Product\Bundle\Actions\Processors\ProductBundleOptionValueCreateProcessor;
35
use TechDivision\Import\Product\Bundle\Actions\Processors\ProductBundleOptionValueUpdateProcessor;
36
use TechDivision\Import\Product\Bundle\Actions\Processors\ProductBundleSelectionCreateProcessor;
37
use TechDivision\Import\Product\Bundle\Actions\Processors\ProductBundleSelectionUpdateProcessor;
38
use TechDivision\Import\Product\Bundle\Actions\Processors\ProductBundleSelectionPriceCreateProcessor;
39
use TechDivision\Import\Product\Bundle\Actions\Processors\ProductBundleSelectionPriceUpdateProcessor;
40
41
/**
42
 * Factory to create a new product bundle processor.
43
 *
44
 * @author    Tim Wagner <[email protected]>
45
 * @copyright 2016 TechDivision GmbH <[email protected]>
46
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
47
 * @link      https://github.com/techdivision/import-cli-simple
48
 * @link      http://www.techdivision.com
49
 */
50
class ProductBundleProcessorFactory extends AbstractProductProcessorFactory
51
{
52
53
    /**
54
     * Return's the processor class name.
55
     *
56
     * @return string The processor class name
57
     */
58
    protected static function getProcessorType()
59
    {
60
        return 'TechDivision\Import\Product\Bundle\Services\ProductBundleProcessor';
61
    }
62
63
    /**
64
     * Factory method to create a new product bundle processor instance.
65
     *
66
     * @param \PDO                                               $connection    The PDO connection to use
67
     * @param TechDivision\Import\Configuration\SubjectInterface $configuration The subject configuration
68
     *
69
     * @return \TechDivision\Import\Product\Bundle\Services\ProductBundleProcessor The processor instance
70
     */
71
    public static function factory(\PDO $connection, SubjectInterface $configuration)
72
    {
73
74
        // load the utility class name
75
        $utilityClassName = $configuration->getUtilityClassName();
76
77
        // initialize the repository that provides bundle option query functionality
78
        $bundleOptionRepository = new BundleOptionRepository();
79
        $bundleOptionRepository->setUtilityClassName($utilityClassName);
80
        $bundleOptionRepository->setConnection($connection);
81
        $bundleOptionRepository->init();
82
83
        // initialize the repository that provides bundle option value query functionality
84
        $bundleOptionValueRepository = new BundleOptionValueRepository();
85
        $bundleOptionValueRepository->setUtilityClassName($utilityClassName);
86
        $bundleOptionValueRepository->setConnection($connection);
87
        $bundleOptionValueRepository->init();
88
89
        // initialize the repository that provides bundle selection query functionality
90
        $bundleSelectionRepository = new BundleSelectionRepository();
91
        $bundleSelectionRepository->setUtilityClassName($utilityClassName);
92
        $bundleSelectionRepository->setConnection($connection);
93
        $bundleSelectionRepository->init();
94
95
        // initialize the repository that provides bundle selection price query functionality
96
        $bundleSelectionPriceRepository = new BundleSelectionPriceRepository();
97
        $bundleSelectionPriceRepository->setUtilityClassName($utilityClassName);
98
        $bundleSelectionPriceRepository->setConnection($connection);
99
        $bundleSelectionPriceRepository->init();
100
101
        // initialize the action that provides product bundle option CRUD functionality
102
        $productBundleOptionCreateProcessor = new ProductBundleOptionCreateProcessor();
103
        $productBundleOptionCreateProcessor->setUtilityClassName($utilityClassName);
104
        $productBundleOptionCreateProcessor->setConnection($connection);
105
        $productBundleOptionCreateProcessor->init();
106
        $productBundleOptionUpdateProcessor = new ProductBundleOptionUpdateProcessor();
107
        $productBundleOptionUpdateProcessor->setUtilityClassName($utilityClassName);
108
        $productBundleOptionUpdateProcessor->setConnection($connection);
109
        $productBundleOptionUpdateProcessor->init();
110
        $productBundleOptionAction = new ProductBundleOptionAction();
111
        $productBundleOptionAction->setCreateProcessor($productBundleOptionCreateProcessor);
112
        $productBundleOptionAction->setUpdateProcessor($productBundleOptionUpdateProcessor);
113
114
        // initialize the action that provides product bundle option CRUD functionality
115
        $productBundleOptionValueCreateProcessor = new ProductBundleOptionValueCreateProcessor();
116
        $productBundleOptionValueCreateProcessor->setUtilityClassName($utilityClassName);
117
        $productBundleOptionValueCreateProcessor->setConnection($connection);
118
        $productBundleOptionValueCreateProcessor->init();
119
        $productBundleOptionValueAction = new ProductBundleOptionValueAction();
120
        $productBundleOptionValueAction->setCreateProcessor($productBundleOptionValueCreateProcessor);
121
122
        // initialize the action that provides product bundle option CRUD functionality
123
        $productBundleSelectionCreateProcessor = new ProductBundleSelectionCreateProcessor();
124
        $productBundleSelectionCreateProcessor->setUtilityClassName($utilityClassName);
125
        $productBundleSelectionCreateProcessor->setConnection($connection);
126
        $productBundleSelectionCreateProcessor->init();
127
        $productBundleSelectionUpdateProcessor = new ProductBundleSelectionUpdateProcessor();
128
        $productBundleSelectionUpdateProcessor->setUtilityClassName($utilityClassName);
129
        $productBundleSelectionUpdateProcessor->setConnection($connection);
130
        $productBundleSelectionUpdateProcessor->init();
131
        $productBundleSelectionAction = new ProductBundleSelectionAction();
132
        $productBundleSelectionAction->setCreateProcessor($productBundleSelectionCreateProcessor);
133
        $productBundleSelectionAction->setUpdateProcessor($productBundleSelectionUpdateProcessor);
134
135
        // initialize the action that provides product bundle option CRUD functionality
136
        $productBundleSelectionPriceCreateProcessor = new ProductBundleSelectionPriceCreateProcessor();
137
        $productBundleSelectionPriceCreateProcessor->setUtilityClassName($utilityClassName);
138
        $productBundleSelectionPriceCreateProcessor->setConnection($connection);
139
        $productBundleSelectionPriceCreateProcessor->init();
140
        $productBundleSelectionPriceUpdateProcessor = new ProductBundleSelectionPriceUpdateProcessor();
141
        $productBundleSelectionPriceUpdateProcessor->setUtilityClassName($utilityClassName);
142
        $productBundleSelectionPriceUpdateProcessor->setConnection($connection);
143
        $productBundleSelectionPriceUpdateProcessor->init();
144
        $productBundleSelectionPriceAction = new ProductBundleSelectionPriceAction();
145
        $productBundleSelectionPriceAction->setCreateProcessor($productBundleSelectionPriceCreateProcessor);
146
        $productBundleSelectionPriceAction->setUpdateProcessor($productBundleSelectionPriceUpdateProcessor);
147
148
        // initialize the product bundle processor
149
        $processorType = ProductBundleProcessorFactory::getProcessorType();
150
        $productBundleProcessor = new $processorType();
151
        $productBundleProcessor->setConnection($connection);
152
        $productBundleProcessor->setBundleOptionRepository($bundleOptionRepository);
153
        $productBundleProcessor->setBundleOptionValueRepository($bundleOptionValueRepository);
154
        $productBundleProcessor->setBundleSelectionRepository($bundleSelectionRepository);
155
        $productBundleProcessor->setBundleSelectionPriceRepository($bundleSelectionPriceRepository);
156
        $productBundleProcessor->setProductBundleOptionAction($productBundleOptionAction);
157
        $productBundleProcessor->setProductBundleOptionValueAction($productBundleOptionValueAction);
158
        $productBundleProcessor->setProductBundleSelectionAction($productBundleSelectionAction);
159
        $productBundleProcessor->setProductBundleSelectionPriceAction($productBundleSelectionPriceAction);
160
161
        // return the instance
162
        return $productBundleProcessor;
163
    }
164
}
165