ShipmentViewFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Factory;
6
7
use Sylius\Component\Core\Model\OrderInterface;
8
use Sylius\Component\Core\Model\ShipmentInterface;
9
use Sylius\ShopApiPlugin\View\ShipmentView;
10
11
final class ShipmentViewFactory implements ShipmentViewFactoryInterface
12
{
13
    /** @var ShippingMethodViewFactoryInterface */
14
    private $shippingMethodViewFactory;
15
16
    /** @var string */
17
    private $shipmentViewClass;
18
19
    public function __construct(ShippingMethodViewFactoryInterface $shippingMethodViewFactory, string $shipmentViewClass)
20
    {
21
        $this->shippingMethodViewFactory = $shippingMethodViewFactory;
22
        $this->shipmentViewClass = $shipmentViewClass;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function create(ShipmentInterface $shipment, string $locale): ShipmentView
29
    {
30
        /** @var OrderInterface $order */
31
        $order = $shipment->getOrder();
32
33
        /** @var ShipmentView $shipmentView */
34
        $shipmentView = new $this->shipmentViewClass();
35
36
        $shipmentView->state = $shipment->getState();
37
        $shipmentView->method = $this->shippingMethodViewFactory->create($shipment, $locale, $order->getCurrencyCode());
38
39
        return $shipmentView;
40
    }
41
}
42