OrderDataExporter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 8
eloc 23
c 2
b 0
f 1
dl 0
loc 90
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A filterData() 0 9 3
A expandData() 0 9 3
A exportData() 0 10 1
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\Minubo\Business\Exporter;
9
10
use SprykerEco\Zed\Minubo\Business\Writer\WriterInterface;
11
use SprykerEco\Zed\Minubo\Persistence\MinuboRepositoryInterface;
12
13
class OrderDataExporter implements DataExporterInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    public const FILE_PREFIX = 'Orders';
19
20
    /**
21
     * @var \SprykerEco\Zed\Minubo\Persistence\MinuboRepositoryInterface
22
     */
23
    protected $repository;
24
25
    /**
26
     * @var array<\SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataFilterInterface>
27
     */
28
    protected $filterPlugins;
29
30
    /**
31
     * @var array<\SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataExpanderInterface>
32
     */
33
    protected $expanderPlugins;
34
35
    /**
36
     * @var \SprykerEco\Zed\Minubo\Business\Writer\WriterInterface
37
     */
38
    protected $writer;
39
40
    /**
41
     * @param \SprykerEco\Zed\Minubo\Persistence\MinuboRepositoryInterface $repository
42
     * @param array<\SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataFilterInterface> $filterPlugins
43
     * @param array<\SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataExpanderInterface> $expanderPlugins
44
     * @param \SprykerEco\Zed\Minubo\Business\Writer\WriterInterface $writer
45
     */
46
    public function __construct(
47
        MinuboRepositoryInterface $repository,
48
        array $filterPlugins,
49
        array $expanderPlugins,
50
        WriterInterface $writer
51
    ) {
52
        $this->repository = $repository;
53
        $this->filterPlugins = $filterPlugins;
54
        $this->expanderPlugins = $expanderPlugins;
55
        $this->writer = $writer;
56
    }
57
58
    /**
59
     * @return void
60
     */
61
    public function exportData(): void
62
    {
63
        $orders = $this->repository
64
            ->getOrderDataUpdatedSinceLastRun();
65
66
        $orders = $this->filterData($orders);
67
68
        $orders = $this->expandData($orders);
69
70
        $this->writer->writeData($orders, static::FILE_PREFIX);
71
    }
72
73
    /**
74
     * @param array<mixed> $orders
75
     *
76
     * @return array
77
     */
78
    protected function filterData(array $orders): array
79
    {
80
        foreach ($orders as $key => $data) {
81
            foreach ($this->filterPlugins as $filter) {
82
                $orders[$key] = $filter->filterData($orders[$key]);
83
            }
84
        }
85
86
        return $orders;
87
    }
88
89
    /**
90
     * @param array<mixed> $orders
91
     *
92
     * @return array
93
     */
94
    protected function expandData(array $orders): array
95
    {
96
        foreach ($orders as $key => $data) {
97
            foreach ($this->expanderPlugins as $expander) {
98
                $orders[$key] = $expander->expandData($orders[$key]);
99
            }
100
        }
101
102
        return $orders;
103
    }
104
}
105