TotalViewFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 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\ShopApiPlugin\View\TotalsView;
9
10
final class TotalViewFactory implements TotalViewFactoryInterface
11
{
12
    /** @var string */
13
    private $totalsViewClass;
14
15
    public function __construct(string $totalsViewClass)
16
    {
17
        $this->totalsViewClass = $totalsViewClass;
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function create(OrderInterface $cart): TotalsView
24
    {
25
        /** @var TotalsView $totalsView */
26
        $totalsView = new $this->totalsViewClass();
27
28
        $totalsView->promotion = $cart->getOrderPromotionTotal();
29
        $totalsView->total = $cart->getTotal();
30
        $totalsView->items = $cart->getItemsTotal();
31
        $totalsView->shipping = $cart->getShippingTotal();
32
        $totalsView->taxes = $cart->getTaxTotal();
33
34
        return $totalsView;
35
    }
36
}
37