Passed
Branch development (62ef01)
by Theodoros
06:18
created

FileExporter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A exportByType() 0 19 2
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\Exporter;
9
10
use Generated\Shared\Transfer\BatchResultTransfer;
11
use Generated\Shared\Transfer\FailedResultTransfer;
12
use Generated\Shared\Transfer\LocaleTransfer;
13
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\CsvNameGenerator;
14
use SprykerEco\Zed\Econda\Business\Exporter\Writer\WriterInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class FileExporter extends AbstractExporter
18
{
19
    /**
20
     * @var \SprykerEco\Zed\Econda\Business\Exporter\Writer\WriterInterface
21
     */
22
    protected $writer;
23
24
    /**
25
     * @var \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\NameGeneratorInterface
26
     */
27
    protected $csvNameGenerator;
28
29
    /**
30
     * @var string
31
     */
32
    protected $exportPath;
33
34
    /**
35
     * FileExporter constructor.
36
     *
37
     * @param \SprykerEco\Zed\Econda\Business\Exporter\Writer\WriterInterface $writer
38
     * @param \Generated\Shared\Transfer\FailedResultTransfer $failedResultTransfer
39
     * @param \Generated\Shared\Transfer\BatchResultTransfer $batchResultTransfer
40
     * @param \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\CsvNameGenerator $csvNameGenerator
41
     * @param string $exportPath
42
     * @param array $collectorPlugins
43
     */
44
    public function __construct(
45
        WriterInterface $writer,
46
        FailedResultTransfer $failedResultTransfer,
47
        BatchResultTransfer $batchResultTransfer,
48
        CsvNameGenerator $csvNameGenerator,
49
        $exportPath,
50
        array $collectorPlugins = []
51
    ) {
52
        parent::__construct(
53
            $writer,
54
            $failedResultTransfer,
55
            $batchResultTransfer,
56
            $collectorPlugins
57
        );
58
59
        $this->csvNameGenerator = $csvNameGenerator;
60
        $this->exportPath = $exportPath;
61
    }
62
63
    /**
64
     * @param string $type
65
     * @param \Generated\Shared\Transfer\LocaleTransfer $localeTransfer
66
     * @param \Symfony\Component\Console\Output\OutputInterface $output
67
     *
68
     * @return \Generated\Shared\Transfer\BatchResultTransfer
69
     */
70
    public function exportByType($type, LocaleTransfer $localeTransfer, OutputInterface $output)
71
    {
72
        $result = $this->getBatchResultTransfer();
73
        $result->setProcessedLocale($localeTransfer);
74
75
        if (!$this->isCollectorRegistered($type)) {
76
            $this->resetResult($result);
77
78
            return $result;
79
        }
80
81
        $fileName = $this->csvNameGenerator->generateFileName($type, $localeTransfer->getLocaleName());
82
        $this->writer->setFileName($fileName);
83
        $this->writer->setFolderPath($this->exportPath);
84
85
        $collectorPlugin = $this->collectorPlugins[$type];
86
        $collectorPlugin->run($localeTransfer, $result, $this->writer, $output);
87
88
        return $result;
89
    }
90
}
91