Passed
Branch development (0519a2)
by Theodoros
02:02
created

EcondaBusinessFactory::getPropelFacade()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Econda\Business;
9
10
use Exception;
11
use Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderDependencyContainer;
0 ignored issues
show
Bug introduced by
The type Spryker\Shared\SqlCriter...lderDependencyContainer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderFactory;
0 ignored issues
show
Bug introduced by
The type Spryker\Shared\SqlCriter...\CriteriaBuilderFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderFactoryWorker;
0 ignored issues
show
Bug introduced by
The type Spryker\Shared\SqlCriter...riaBuilderFactoryWorker was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Spryker\Zed\Kernel\Business\AbstractBusinessFactory;
0 ignored issues
show
Bug introduced by
The type Spryker\Zed\Kernel\Busin...AbstractBusinessFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use SprykerEco\Zed\Econda\Business\Collector\File\EcondaCategoryCollector;
16
use SprykerEco\Zed\Econda\Business\Collector\File\EcondaProductCollector;
17
use SprykerEco\Zed\Econda\Business\Exporter\FileExporter;
18
use SprykerEco\Zed\Econda\Business\Exporter\Runner;
19
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\Adapter\CsvAdapter;
20
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\FileWriter;
21
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\CsvNameGenerator;
22
use SprykerEco\Zed\Econda\Business\Helper\ProgressBarHelper;
23
use SprykerEco\Zed\Econda\Business\Manager\CollectorManager;
24
use SprykerEco\Zed\Econda\Business\Model\BatchResult;
25
use SprykerEco\Zed\Econda\Business\Model\FailedResult;
26
use SprykerEco\Zed\Econda\Business\Reader\EcondaCsvFileReader;
27
use SprykerEco\Zed\Econda\EcondaDependencyProvider;
28
use SprykerEco\Zed\Econda\Persistence\EcondaQueryContainer;
29
30
/**
31
 * @method \SprykerEco\Zed\Econda\EcondaConfig getConfig()
32
 * @method \SprykerEco\Zed\Econda\Persistence\EcondaQueryContainer getQueryContainer()
33
 */
34
class EcondaBusinessFactory extends AbstractBusinessFactory
35
{
36
37
    /**
38
     * @param string $type
39
     * @param string $locale
40
     *
41
     * @return string
42
     */
43
    public function getEcondaCsvFileContent($type, $locale)
44
    {
45
        $nameGenerator = $this->createCsvNameGenerator();
46
        $reader = new EcondaCsvFileReader($this->getConfig(), $nameGenerator);
47
        return $reader->readFile($type, $locale);
48
    }
49
50
    /**
51
     * @return \SprykerEco\Zed\Econda\Business\Exporter\Runner
52
     */
53
    public function createRunner()
54
    {
55
        return new Runner(
56
            $this->getLocaleFacade(),
57
            $this->createFileExporter()
58
        );
59
    }
60
61
    /**
62
     * @return \SprykerEco\Zed\Econda\Business\Manager\CollectorManager
63
     */
64
    public function createCollectorManager()
65
    {
66
        $criteriaBuilder = $this->createCriteriaBuilder();
67
        $queryContainer = $this->getEcondaQueryContainer();
68
        $progressBarHelper = $this->createProgressBarHelper();
69
        return new CollectorManager($criteriaBuilder, $queryContainer, $progressBarHelper);
70
    }
71
72
    /**
73
     * @return \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\FileWriter
74
     */
75
    protected function createFileWriter()
76
    {
77
        $csvFileWriterAdapter = $this->createCsvFileWriterAdapter();
78
        $fileWriter = new FileWriter($csvFileWriterAdapter);
79
80
        return $fileWriter;
81
    }
82
83
    /**
84
     * @return \SprykerEco\Zed\Econda\Business\Model\BatchResult
85
     */
86
    protected function createBatchResultModel()
87
    {
88
        return new BatchResult();
0 ignored issues
show
Deprecated Code introduced by
The class SprykerEco\Zed\Econda\Business\Model\BatchResult has been deprecated: Must be refactored into a Transfer object instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

88
        return /** @scrutinizer ignore-deprecated */ new BatchResult();
Loading history...
89
    }
90
91
    /**
92
     * @return \SprykerEco\Zed\Econda\Business\Helper\ProgressBarHelper
93
     */
94
    protected function createProgressBarHelper()
95
    {
96
        return new ProgressBarHelper();
97
    }
98
99
    /**
100
     * @return \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\CsvNameGenerator
101
     */
102
    protected function createCsvNameGenerator()
103
    {
104
        return new CsvNameGenerator();
105
    }
106
107
    /**
108
     * @return \SprykerEco\Zed\Econda\Business\Collector\File\EcondaCategoryCollector
109
     */
110
    public function createFileCategoryCollector()
111
    {
112
        $storageCategoryNodeCollector = new EcondaCategoryCollector(
113
            $this->createCriteriaBuilder(),
114
            $this->createStoragePdoQueryAdapterByName('CategoryNodeEcondaQuery')
115
        );
116
117
        return $storageCategoryNodeCollector;
118
    }
119
120
    /**
121
     * @return \SprykerEco\Zed\Econda\Business\Collector\File\EcondaProductCollector
122
     */
123
    public function createFileProductCollector()
124
    {
125
        /**
126
         * @var \SprykerEco\Zed\Econda\Business\Collector\File\EcondaProductCollector $storageProductCollector
127
         */
128
        $storageProductCollector = new EcondaProductCollector(
129
            $this->createCriteriaBuilder(),
130
            $this->createStoragePdoQueryAdapterByName('ProductConcreteEcondaQuery'),
131
            $this->getProductCategoryQueryContainer(),
132
            $this->getProductImageQueryContainer(),
133
            $this->getPriceFacade(),
134
            $this->getConfig()
135
        );
136
137
        return $storageProductCollector;
138
    }
139
140
    /**
141
     * @return \SprykerEco\Zed\Econda\Business\Exporter\ExporterInterface
142
     */
143
    protected function createFileExporter()
144
    {
145
        $fileExporter = new FileExporter(
146
            $this->createFileWriter(),
147
            $this->createFailedResultModel(),
148
            $this->createBatchResultModel(),
149
            $this->createCsvNameGenerator(),
150
            $this->getConfig()->getFileExportPath(),
151
            $this->getCollectorFileExporterPlugins()
152
        );
153
154
        return $fileExporter;
155
    }
156
157
    /**
158
     * @return \SprykerEco\Zed\Econda\Dependency\Plugin\EcondaPluginInterface[]
159
     */
160
    protected function getCollectorFileExporterPlugins()
161
    {
162
        return $this->getProvidedDependency(EcondaDependencyProvider::FILE_PLUGINS);
163
    }
164
165
    /**
166
     * @return \SprykerEco\Zed\Econda\Dependency\Facade\EcondaToLocaleInterface
167
     */
168
    protected function getLocaleFacade()
169
    {
170
        return $this->getProvidedDependency(EcondaDependencyProvider::FACADE_LOCALE);
171
    }
172
173
    /**
174
     * @return \SprykerEco\Zed\Econda\Persistence\EcondaQueryContainer
175
     */
176
    protected function getEcondaQueryContainer()
177
    {
178
        return new EcondaQueryContainer();
179
    }
180
181
    /**
182
     * @return \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\Adapter\CsvAdapter
183
     */
184
    protected function createCsvFileWriterAdapter()
185
    {
186
        return new CsvAdapter($this->getConfig()->getFileExportPath());
187
    }
188
189
    /**
190
     * @return \SprykerEco\Zed\Econda\Business\Model\FailedResult
191
     */
192
    protected function createFailedResultModel()
193
    {
194
        return new FailedResult();
0 ignored issues
show
Deprecated Code introduced by
The class SprykerEco\Zed\Econda\Business\Model\FailedResult has been deprecated: Must be refactored into a Transfer object instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

194
        return /** @scrutinizer ignore-deprecated */ new FailedResult();
Loading history...
195
    }
196
197
    /**
198
     * @return string
199
     */
200
    protected function getCurrentDatabaseEngineName()
201
    {
202
        return $this->getPropelFacade()->getCurrentDatabaseEngineName();
203
    }
204
205
    /**
206
     * @return \Spryker\Zed\ProductImage\Persistence\ProductImageQueryContainerInterface
0 ignored issues
show
Bug introduced by
The type Spryker\Zed\ProductImage...QueryContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
207
     */
208
    protected function getProductImageQueryContainer()
209
    {
210
        return $this->getProvidedDependency(EcondaDependencyProvider::QUERY_CONTAINER_PRODUCT_IMAGE);
211
    }
212
213
    /**
214
     * @param string $name
215
     *
216
     * @throws \Exception
217
     *
218
     * @return \SprykerEco\Zed\Econda\Persistence\Econda\AbstractPdoEcondaQuery
219
     */
220
    protected function createStoragePdoQueryAdapterByName($name)
221
    {
222
        $classList = $this->getConfig()->getStoragePdoQueryAdapterClassNames(
223
            $this->getCurrentDatabaseEngineName()
224
        );
225
        if (!array_key_exists($name, $classList)) {
226
            throw new Exception('Invalid StoragePdoQueryAdapter name: ' . $name);
227
        }
228
229
        $queryBuilderClassName = $classList[$name];
230
231
        return new $queryBuilderClassName();
232
    }
233
234
    /**
235
     * @return \Spryker\Zed\Propel\Business\PropelFacadeInterface
0 ignored issues
show
Bug introduced by
The type Spryker\Zed\Propel\Business\PropelFacadeInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
236
     */
237
    protected function getPropelFacade()
238
    {
239
        return $this->getProvidedDependency(EcondaDependencyProvider::FACADE_PROPEL);
240
    }
241
242
    /**
243
     * @return \Spryker\Zed\Price\Business\PriceFacadeInterface
0 ignored issues
show
Bug introduced by
The type Spryker\Zed\Price\Business\PriceFacadeInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
244
     */
245
    protected function getPriceFacade()
246
    {
247
        return $this->getProvidedDependency(EcondaDependencyProvider::FACADE_PRICE);
248
    }
249
250
    /**
251
     * @return \Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderInterface
0 ignored issues
show
Bug introduced by
The type Spryker\Shared\SqlCriter...riteriaBuilderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
252
     */
253
    protected function createCriteriaBuilder()
254
    {
255
        $factory = new CriteriaBuilderFactory(
256
            $this->createCriteriaBuilderContainer()
257
        );
258
259
        $factory->registerWorkerCallback('CriteriaBuilderFactoryWorker', function () use ($factory) {
260
            return $factory->buildWorker(CriteriaBuilderFactoryWorker::class);
261
        });
262
263
        /** @var \Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderFactoryWorker $factoryWorker */
264
        $factoryWorker = $factory->getWorkerByName('CriteriaBuilderFactoryWorker');
265
266
        return $factoryWorker->buildCriteriaBuilder();
267
    }
268
269
    /**
270
     * @return \Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderDependencyContainer
271
     */
272
    protected function createCriteriaBuilderContainer()
273
    {
274
        return new CriteriaBuilderDependencyContainer();
275
    }
276
277
    /**
278
     * @return \Spryker\Zed\ProductCategory\Persistence\ProductCategoryQueryContainerInterface
0 ignored issues
show
Bug introduced by
The type Spryker\Zed\ProductCateg...QueryContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
279
     */
280
    protected function getProductCategoryQueryContainer()
281
    {
282
        return $this->getProvidedDependency(EcondaDependencyProvider::QUERY_CONTAINER_PRODUCT_CATEGORY);
283
    }
284
285
}
286