1 | <?php |
||
14 | final class ProductBuilder implements ProductBuilderInterface |
||
15 | { |
||
16 | /** |
||
17 | * @return Product[] |
||
18 | */ |
||
19 | 3 | public function buildFromArray(array $products, Currency $currency): array |
|
20 | { |
||
21 | 3 | $data = []; |
|
22 | |||
23 | 3 | foreach ($products as $product) { |
|
24 | 3 | $data[] = $this->build($product, $currency); |
|
25 | } |
||
26 | |||
27 | 3 | return $data; |
|
28 | } |
||
29 | |||
30 | 3 | private function build(array $product, Currency $currency): Product |
|
31 | { |
||
32 | 3 | return new Product( |
|
33 | 3 | $this->getUuidFromKey('productUuid', $product), |
|
34 | 3 | $this->getUuidFromKey('variantUuid', $product), |
|
35 | 3 | $this->getFromKey('name', $product), |
|
36 | 3 | $this->getFromKey('variantName', $product), |
|
37 | 3 | $this->getIntFromKey('quantity', $product), |
|
38 | 3 | $this->getMoneyFromKey('unitPrice', $currency, $product), |
|
39 | 3 | $this->getFromKey('vatPercentage', $product), |
|
40 | 3 | $this->getMoneyFromKey('rowTaxableAmount', $currency, $product), |
|
41 | 3 | $this->getImageFromKey('imageLookupKey', $product), |
|
42 | 3 | $this->getFromKey('autoGenerated', $product), |
|
43 | 3 | $this->getFromKey('libraryProduct', $product) |
|
44 | ); |
||
45 | } |
||
46 | |||
47 | 3 | private function getFromKey($key, array $data) |
|
55 | |||
56 | 3 | private function getIntFromKey(string $key, array $data): int |
|
60 | |||
61 | 3 | private function getUuidFromKey(string $key, array $data): ?UuidInterface |
|
70 | |||
71 | 3 | private function getMoneyFromKey(string $key, Currency $currency, array $data): Money |
|
75 | |||
76 | 3 | private function getImageFromKey(string $key, array $data): ?Image |
|
85 | } |
||
86 |