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

PaymentViewFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 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\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);
0 ignored issues
show
Compatibility introduced by
$payment->getMethod() of type object<Sylius\Component\...PaymentMethodInterface> is not a sub-type of object<Sylius\Component\...PaymentMethodInterface>. It seems like you assume a child interface of the interface Sylius\Component\Payment...\PaymentMethodInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
41
        $paymentView->price = $this->priceViewFactory->create($payment->getAmount(), $payment->getCurrencyCode());
42
43
        return $paymentView;
44
    }
45
}
46