ShipmentViewFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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