PaymentViewFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLagersystemPlugin\Factory;
6
7
use Setono\SyliusLagersystemPlugin\View\PaymentView;
8
use Sylius\Component\Core\Model\PaymentInterface;
9
use Sylius\Component\Core\Model\PaymentMethodInterface;
10
use Webmozart\Assert\Assert;
11
12
class PaymentViewFactory implements PaymentViewFactoryInterface
13
{
14
    /** @var PaymentMethodViewFactoryInterface */
15
    protected $paymentMethodViewFactory;
16
17
    /** @var string */
18
    protected $paymentViewClass;
19
20
    public function __construct(
21
        PaymentMethodViewFactoryInterface $paymentMethodViewFactory,
22
        string $paymentViewClass
23
    ) {
24
        $this->paymentMethodViewFactory = $paymentMethodViewFactory;
25
        $this->paymentViewClass = $paymentViewClass;
26
    }
27
28
    public function create(PaymentInterface $payment, string $locale): PaymentView
29
    {
30
        /** @var PaymentMethodInterface|null $paymentMethod */
31
        $paymentMethod = $payment->getMethod();
32
        Assert::notNull($paymentMethod);
33
34
        /** @var PaymentView $paymentView */
35
        $paymentView = new $this->paymentViewClass();
36
        $paymentView->state = $payment->getState();
37
        $paymentView->method = $this->paymentMethodViewFactory->create($paymentMethod, $locale);
38
39
        return $paymentView;
40
    }
41
}
42