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

PaymentMethodViewFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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