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

AdjustmentViewFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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