ConvertRefundData::getTotal()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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