PaymentMethodFactory::createWithGateway()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PH\Component\Core\Factory;
6
7
use PH\Component\Core\Model\PaymentMethodInterface;
8
use Sylius\Component\Resource\Factory\FactoryInterface;
9
10
final class PaymentMethodFactory implements PaymentMethodFactoryInterface
11
{
12
    /**
13
     * @var FactoryInterface
14
     */
15
    private $decoratedFactory;
16
17
    /**
18
     * @var FactoryInterface
19
     */
20
    private $gatewayConfigFactory;
21
22
    /**
23
     * @param FactoryInterface $decoratedFactory
24
     * @param FactoryInterface $gatewayConfigFactory
25
     */
26
    public function __construct(FactoryInterface $decoratedFactory, FactoryInterface $gatewayConfigFactory)
27
    {
28
        $this->decoratedFactory = $decoratedFactory;
29
        $this->gatewayConfigFactory = $gatewayConfigFactory;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function createNew(): PaymentMethodInterface
36
    {
37
        return $this->decoratedFactory->createNew();
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function createWithGateway(string $gatewayFactory): PaymentMethodInterface
44
    {
45
        $gatewayConfig = $this->gatewayConfigFactory->createNew();
46
        $gatewayConfig->setFactoryName($gatewayFactory);
47
48
        /** @var PaymentMethodInterface $paymentMethod */
49
        $paymentMethod = $this->decoratedFactory->createNew();
50
        $paymentMethod->setGatewayConfig($gatewayConfig);
51
52
        return $paymentMethod;
53
    }
54
}
55