Completed
Push — npm-shrinkwrap ( 52ca24 )
by Kamil
23:13
created

PaymentMethodFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createNew() 0 4 1
A createWithGateway() 0 11 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Core\Factory;
13
14
use Sylius\Component\Core\Model\PaymentMethodInterface;
15
use Sylius\Component\Resource\Factory\FactoryInterface;
16
17
/**
18
 * @author Mateusz Zalewski <[email protected]>
19
 */
20
final class PaymentMethodFactory implements PaymentMethodFactoryInterface
21
{
22
    /**
23
     * @var FactoryInterface
24
     */
25
    private $decoratedFactory;
26
27
    /**
28
     * @var FactoryInterface
29
     */
30
    private $gatewayConfigFactory;
31
32
    /**
33
     * @param FactoryInterface $decoratedFactory
34
     * @param FactoryInterface $gatewayConfigFactory
35
     */
36
    public function __construct(FactoryInterface $decoratedFactory, FactoryInterface $gatewayConfigFactory)
37
    {
38
        $this->decoratedFactory = $decoratedFactory;
39
        $this->gatewayConfigFactory = $gatewayConfigFactory;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function createNew()
46
    {
47
        return $this->decoratedFactory->createNew();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function createWithGateway($gatewayFactory)
54
    {
55
        $gatewayConfig = $this->gatewayConfigFactory->createNew();
56
        $gatewayConfig->setFactoryName($gatewayFactory);
57
58
        /** @var PaymentMethodInterface $paymentMethod */
59
        $paymentMethod = $this->decoratedFactory->createNew();
60
        $paymentMethod->setGatewayConfig($gatewayConfig);
61
62
        return $paymentMethod;
63
    }
64
}
65