Completed
Push — master ( b7e254...bcf326 )
by
unknown
09:07
created

PaymentRefundCalculator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

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

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
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusMolliePlugin\Calculator\Refund;
14
15
use BitBag\SyliusMolliePlugin\DTO\PartialRefundItem;
16
use BitBag\SyliusMolliePlugin\DTO\PartialRefundItems;
17
18
final class PaymentRefundCalculator implements PaymentRefundCalculatorInterface
19
{
20
    public function calculate(PartialRefundItems $partialRefundItems, int $totalToRefund): PartialRefundItems
21
    {
22
        /** @var PartialRefundItem $partialRefundItem */
23
        foreach ($partialRefundItems->getPartialRefundItems() as $partialRefundItem) {
24
            if ($partialRefundItem->getAvailableAmountToRefund() > 0) {
25
                $totalToRefund = $partialRefundItem->setAmountToRefund($totalToRefund);
26
                if ($totalToRefund === 0) {
27
                    break;
28
                }
29
            }
30
        }
31
32
        return $partialRefundItems;
33
    }
34
}
35