Passed
Pull Request — master (#99)
by
unknown
07:43
created

ApplePayEnabledChecker::isEnabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
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\Checker\ApplePay;
13
14
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface;
15
use Mollie\Api\Types\PaymentMethod;
16
use Sylius\Component\Resource\Repository\RepositoryInterface;
17
18
final class ApplePayEnabledChecker implements ApplePayEnabledCheckerInterface
19
{
20
    /** @var RepositoryInterface */
21
    private $mollieGatewayConfigurationRepository;
22
23
    public function __construct(RepositoryInterface $mollieGatewayConfigurationRepository)
24
    {
25
        $this->mollieGatewayConfigurationRepository = $mollieGatewayConfigurationRepository;
26
    }
27
28
    public function isEnabled(): bool
29
    {
30
        $applePayConfig = $this->mollieGatewayConfigurationRepository->findOneBy([
31
            'methodId' => PaymentMethod::APPLEPAY,
32
        ]);
33
34
        if ($applePayConfig instanceof MollieGatewayConfigInterface) {
35
            return $applePayConfig->isApplePayDirectButton();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $applePayConfig->isApplePayDirectButton() could return the type null which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
36
        }
37
38
        return false;
39
    }
40
}
41