Failed Conditions
Pull Request — master (#188)
by Kamil
04:26
created

TotalViewFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

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