PaymentViewFactory::create()   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 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Factory;
6
7
use Sylius\Component\Core\Model\PaymentInterface;
8
use Sylius\ShopApiPlugin\View\PaymentView;
9
10
final class PaymentViewFactory implements PaymentViewFactoryInterface
11
{
12
    /** @var PaymentMethodViewFactoryInterface */
13
    private $paymentMethodViewFactory;
14
15
    /** @var PriceViewFactoryInterface */
16
    private $priceViewFactory;
17
18
    /** @var string */
19
    private $paymentViewClass;
20
21
    public function __construct(
22
        PaymentMethodViewFactoryInterface $paymentMethodViewFactory,
23
        PriceViewFactoryInterface $priceViewFactory,
24
        string $paymentViewClass
25
    ) {
26
        $this->paymentMethodViewFactory = $paymentMethodViewFactory;
27
        $this->priceViewFactory = $priceViewFactory;
28
        $this->paymentViewClass = $paymentViewClass;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function create(PaymentInterface $payment, string $locale): PaymentView
35
    {
36
        /** @var PaymentView $paymentView */
37
        $paymentView = new $this->paymentViewClass();
38
39
        $paymentView->state = $payment->getState();
40
        $paymentView->method = $this->paymentMethodViewFactory->create($payment->getMethod(), $locale);
41
        $paymentView->price = $this->priceViewFactory->create($payment->getAmount(), $payment->getCurrencyCode());
42
43
        return $paymentView;
44
    }
45
}
46