Completed
Pull Request — master (#290)
by
unknown
41:51
created

PaymentMethodViewFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\SyliusShopApiPlugin\Factory;
6
7
use Sylius\Component\Core\Model\PaymentMethodInterface;
8
use Sylius\ShopApiPlugin\View\PaymentMethodView;
9
10
final class PaymentMethodViewFactory implements PaymentMethodViewFactoryInterface
11
{
12
    /** @var string */
13
    private $paymentMethodViewClass;
14
15
    public function __construct(string $paymentMethodViewClass)
16
    {
17
        $this->paymentMethodViewClass = $paymentMethodViewClass;
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function create(PaymentMethodInterface $paymentMethod, string $locale): PaymentMethodView
24
    {
25
        /** @var PaymentMethodView $paymentMethodView */
26
        $paymentMethodView = new $this->paymentMethodViewClass();
27
28
        $paymentMethodView->code = $paymentMethod->getCode();
29
        $paymentMethodView->name = $paymentMethod->getTranslation($locale)->getName();
30
        $paymentMethodView->description = $paymentMethod->getTranslation($locale)->getDescription();
31
32
        return $paymentMethodView;
33
    }
34
}
35