Completed
Push — master ( 98b142...a3a13d )
by Paweł
02:49
created

PaymentViewFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Factory;
4
5
use Sylius\Component\Core\Model\PaymentInterface;
6
use Sylius\ShopApiPlugin\View\PaymentView;
7
8
final class PaymentViewFactory implements PaymentViewFactoryInterface
9
{
10
    /**
11
     * @var PaymentMethodViewFactoryInterface
12
     */
13
    private $paymentMethodViewFactory;
14
15
    /**
16
     * @var PriceViewFactoryInterface
17
     */
18
    private $priceViewFactory;
19
20
    /**
21
     * @param PaymentMethodViewFactoryInterface $paymentMethodViewFactory
22
     * @param PriceViewFactoryInterface $priceViewFactory
23
     */
24
    public function __construct(PaymentMethodViewFactoryInterface $paymentMethodViewFactory, PriceViewFactoryInterface $priceViewFactory)
25
    {
26
        $this->paymentMethodViewFactory = $paymentMethodViewFactory;
27
        $this->priceViewFactory = $priceViewFactory;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function create(PaymentInterface $payment, $locale)
34
    {
35
        $paymentView = new PaymentView();
36
37
        $paymentView->state = $payment->getState();
38
        $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...
39
        $paymentView->price = $this->priceViewFactory->create($payment->getAmount());
40
41
        return $paymentView;
42
    }
43
}
44