Completed
Pull Request — master (#290)
by
unknown
41:51
created

AdjustmentViewFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
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 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\SyliusShopApiPlugin\Factory;
6
7
use Sylius\Component\Order\Model\AdjustmentInterface;
8
use Sylius\ShopApiPlugin\View\AdjustmentView;
9
10
final class AdjustmentViewFactory implements AdjustmentViewFactoryInterface
11
{
12
    /** @var PriceViewFactoryInterface */
13
    private $priceViewFactory;
14
15
    /** @var string */
16
    private $adjustmentViewClass;
17
18
    public function __construct(PriceViewFactoryInterface $priceViewFactory, string $adjustmentViewClass)
19
    {
20
        $this->priceViewFactory = $priceViewFactory;
21
        $this->adjustmentViewClass = $adjustmentViewClass;
22
    }
23
24
    public function create(AdjustmentInterface $adjustment, int $additionalAmount, string $currency): AdjustmentView
25
    {
26
        /** @var AdjustmentView $adjustmentView */
27
        $adjustmentView = new $this->adjustmentViewClass();
28
29
        $adjustmentView->name = $adjustment->getLabel();
30
        $adjustmentView->amount = $this->priceViewFactory->create($adjustment->getAmount() + $additionalAmount, $currency);
31
32
        return $adjustmentView;
33
    }
34
}
35