MollieGatewayConfigFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 19 1
A __construct() 0 4 1
A createNewOrUpdate() 0 8 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\Factory;
13
14
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface;
15
use BitBag\SyliusMolliePlugin\Payments\Methods\MethodInterface;
16
use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface;
17
use Sylius\Component\Resource\Factory\FactoryInterface;
18
use Sylius\Component\Resource\Repository\RepositoryInterface;
19
20
final class MollieGatewayConfigFactory implements MollieGatewayConfigFactoryInterface
21
{
22
    /** @var FactoryInterface */
23
    private $mollieGatewayConfigFactory;
24
25
    /** @var RepositoryInterface */
26
    private $repository;
27
28
    public function __construct(FactoryInterface $mollieGatewayConfigFactory, RepositoryInterface $repository)
29
    {
30
        $this->mollieGatewayConfigFactory = $mollieGatewayConfigFactory;
31
        $this->repository = $repository;
32
    }
33
34
    private function createNewOrUpdate(MethodInterface $method, GatewayConfigInterface $gateway): MollieGatewayConfigInterface
35
    {
36
        $methodExist = $this->repository->findOneBy([
37
            'methodId' => $method->getMethodId(),
0 ignored issues
show
Bug introduced by
The method getMethodId() does not exist on BitBag\SyliusMolliePlugi...Methods\MethodInterface. It seems like you code against a sub-type of said class. However, the method does not exist in BitBag\SyliusMolliePlugi...\Methods\AbstractMethod. 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

37
            'methodId' => $method->/** @scrutinizer ignore-call */ getMethodId(),
Loading history...
38
            'gateway' => $gateway,
39
        ]);
40
41
        return null !== $methodExist ? $methodExist : $this->mollieGatewayConfigFactory->createNew();
42
    }
43
44
    public function create(
45
        MethodInterface $method,
46
        GatewayConfigInterface $gateway,
47
        int $key
48
    ): MollieGatewayConfigInterface {
49
        $mollieGatewayConfig = $this->createNewOrUpdate($method, $gateway);
50
51
        $mollieGatewayConfig->setMethodId($method->getMethodId());
52
        $mollieGatewayConfig->setName($method->getName());
53
        $mollieGatewayConfig->setMinimumAmount($method->getMinimumAmount());
54
        $mollieGatewayConfig->setMaximumAmount($method->getMinimumAmount());
55
        $mollieGatewayConfig->setImage($method->getImage());
56
        $mollieGatewayConfig->setGateway($gateway);
57
        $mollieGatewayConfig->setIssuers($method->getIssuers());
58
        $mollieGatewayConfig->setPaymentType($method->getPaymentType());
59
        $mollieGatewayConfig->setApplePayDirectButton(false);
60
        $mollieGatewayConfig->setPosition($key);
61
62
        return $mollieGatewayConfig;
63
    }
64
}
65