ConvertRefundData   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getTotal() 0 5 2
A convert() 0 13 3
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusMolliePlugin\Helper;
13
14
use Sylius\RefundPlugin\Model\OrderItemUnitRefund;
15
use Sylius\RefundPlugin\Model\ShipmentRefund;
16
17
final class ConvertRefundData implements ConvertRefundDataInterface
18
{
19
    /** @var IntToStringConverter */
20
    private $intToStringConverter;
21
22
    public function __construct(IntToStringConverter $intToStringConverter)
23
    {
24
        $this->intToStringConverter = $intToStringConverter;
25
    }
26
27
    public function convert(array $data, string $currency): array
28
    {
29
        $value = 0;
30
31
        foreach ($data as $items) {
32
            foreach ($this->getTotal($items) as $total) {
33
                $value += $total;
34
            }
35
        }
36
37
        return [
38
            'currency' => $currency,
39
            'value' => $this->intToStringConverter->convertIntToString($value, 100),
40
        ];
41
    }
42
43
    private function getTotal(array $refundsData): iterable
44
    {
45
        /** @var OrderItemUnitRefund|ShipmentRefund $data */
46
        foreach ($refundsData as $refundData) {
47
            yield $refundData->total();
48
        }
49
    }
50
}
51