Passed
Pull Request — master (#133)
by
unknown
06:53
created

MollieAmountRestrictionResolver::resolve()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 4
c 1
b 0
f 1
nc 2
nop 3
dl 0
loc 7
rs 10
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\Resolver;
13
14
15
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface;
16
use Sylius\Component\Core\Model\OrderInterface;
17
18
final class MollieAmountRestrictionResolver implements MollieAmountRestrictionResolverInterface
19
{
20
    public function resolve(MollieGatewayConfigInterface $paymentMethod, array $methods, OrderInterface $order): array
21
    {
22
        if ($order->getTotal() < $paymentMethod->getMinimumAmount() ||
23
            $order->getTotal() > $paymentMethod->getMaximumAmount()) {
24
            return $this->removePaymentMethod($paymentMethod, $methods);
25
        }
26
        return $methods;
27
    }
28
29
    private function removePaymentMethod(MollieGatewayConfigInterface $paymentMethod, array $methods): array
30
    {
31
        unset(
32
            $methods['data'][$paymentMethod->getName()],
33
            $methods['image'][$paymentMethod->getMethodId()],
34
            $methods['issuers'][$paymentMethod->getMethodId()],
35
            $methods['paymentFee'][$paymentMethod->getMethodId()]
36
        );
37
38
        return $methods;
39
    }
40
}
41