Failed Conditions
Pull Request — master (#175)
by Łukasz
04:12
created

AdjustmentViewFactory::create()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 1
nop 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sylius\ShopApiPlugin\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
    public function __construct(PriceViewFactoryInterface $priceViewFactory)
16
    {
17
        $this->priceViewFactory = $priceViewFactory;
18
    }
19
20
    public function create(AdjustmentInterface $adjustment, ?AdjustmentView $additionalAmount): AdjustmentView
21
    {
22
        $adjustmentView = new AdjustmentView();
23
24
        $adjustmentView->name = $adjustment->getLabel();
25
        $adjustmentView->amount = $this->priceViewFactory->create(
26
            $additionalAmount ? $adjustment->getAmount() + $additionalAmount->amount->current : $adjustment->getAmount()
27
        );
28
29
        return $adjustmentView;
30
    }
31
}
32