Completed
Pull Request — master (#188)
by Kamil
03:23
created

TotalViewFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Factory;
4
5
use Sylius\Component\Core\Model\OrderInterface;
6
use Sylius\ShopApiPlugin\View\TotalsView;
7
8
final class TotalViewFactory implements TotalViewFactoryInterface
9
{
10
    /** @var string */
11
    private $totalsViewClass;
12
13
    public function __construct(string $totalsViewClass)
14
    {
15
        $this->totalsViewClass = $totalsViewClass;
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function create(OrderInterface $cart): TotalsView
22
    {
23
        /** @var TotalsView $totalsView */
24
        $totalsView = new $this->totalsViewClass();
25
26
        $totalsView->promotion = $cart->getOrderPromotionTotal();
27
        $totalsView->total = $cart->getTotal();
28
        $totalsView->items = $cart->getItemsTotal();
29
        $totalsView->shipping = $cart->getShippingTotal();
30
        $totalsView->taxes = $cart->getTaxTotal();
31
32
        return $totalsView;
33
    }
34
}
35