PaymentRefundCalculator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A calculate() 0 13 4
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\Calculator\Refund;
13
14
use BitBag\SyliusMolliePlugin\DTO\PartialRefundItem;
15
use BitBag\SyliusMolliePlugin\DTO\PartialRefundItems;
16
17
final class PaymentRefundCalculator implements PaymentRefundCalculatorInterface
18
{
19
    public function calculate(PartialRefundItems $partialRefundItems, int $totalToRefund): PartialRefundItems
20
    {
21
        /** @var PartialRefundItem $partialRefundItem */
22
        foreach ($partialRefundItems->getPartialRefundItems() as $partialRefundItem) {
23
            if ($partialRefundItem->getAvailableAmountToRefund() > 0) {
24
                $totalToRefund = $partialRefundItem->setAmountToRefund($totalToRefund);
25
                if ($totalToRefund === 0) {
26
                    break;
27
                }
28
            }
29
        }
30
31
        return $partialRefundItems;
32
    }
33
}
34