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

PaymentViewFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 10 1
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