provideApplePayPayment()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 20
rs 9.9666
cc 3
nc 3
nop 2
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\Provider\Apple;
13
14
use BitBag\SyliusMolliePlugin\Entity\GatewayConfigInterface;
15
use BitBag\SyliusMolliePlugin\Resolver\ApplePayDirect\ApplePayDirectPaymentTypeResolverInterface;
16
use Mollie\Api\Types\PaymentMethod;
17
use Sylius\Component\Core\Model\PaymentInterface;
18
use Sylius\Component\Core\Model\PaymentMethodInterface;
19
use Sylius\Component\Order\Model\OrderInterface;
20
21
final class ApplePayDirectPaymentProvider implements ApplePayDirectPaymentProviderInterface
22
{
23
    /** @var ApplePayDirectPaymentTypeResolverInterface */
24
    private $applePayDirectPaymentTypeResolver;
25
26
    public function __construct(ApplePayDirectPaymentTypeResolverInterface $applePayDirectPaymentTypeResolver)
27
    {
28
        $this->applePayDirectPaymentTypeResolver = $applePayDirectPaymentTypeResolver;
29
    }
30
31
    public function provideApplePayPayment(OrderInterface $order, array $applePayPaymentToken): void
32
    {
33
        /** @var PaymentInterface $paymentMethod */
34
        $payment = $order->getLastPayment();
0 ignored issues
show
Bug introduced by
The method getLastPayment() does not exist on Sylius\Component\Order\Model\OrderInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sylius\Component\Order\Model\Order. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        /** @scrutinizer ignore-call */ 
35
        $payment = $order->getLastPayment();
Loading history...
35
        /** @var PaymentMethodInterface $paymentMethod */
36
        $paymentMethod = $payment->getMethod();
37
        /** @var GatewayConfigInterface $gatewayConfig */
38
        $gatewayConfig = $paymentMethod->getGatewayConfig();
39
40
        if ($gatewayConfig->getMollieGatewayConfig()->isEmpty()) {
41
            return;
42
        }
43
44
        $applePayConfig = $gatewayConfig->getMethodByName(PaymentMethod::APPLEPAY);
0 ignored issues
show
Bug introduced by
The method getMethodByName() does not exist on BitBag\SyliusMolliePlugi...\GatewayConfigInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to BitBag\SyliusMolliePlugi...\GatewayConfigInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        /** @scrutinizer ignore-call */ 
45
        $applePayConfig = $gatewayConfig->getMethodByName(PaymentMethod::APPLEPAY);
Loading history...
45
46
        if (!$applePayConfig->isEnabled()) {
47
            return;
48
        }
49
50
        $this->applePayDirectPaymentTypeResolver->resolve($applePayConfig, $payment, $applePayPaymentToken);
51
    }
52
}
53