BasketItemMapper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 79
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A map() 0 24 2
A initBasketIfEmpty() 0 4 2
A getBasketItemDiscount() 0 6 1
A __construct() 0 8 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Ratepay\Business\Api\Mapper;
9
10
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Generated\Shared\Transfer\RatepayRequestShoppingBasketItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ppingBasketItemTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Generated\Shared\Transfer\RatepayRequestShoppingBasketTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...tShoppingBasketTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Generated\Shared\Transfer\RatepayRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RatepayRequestTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use SprykerEco\Zed\Ratepay\Dependency\Facade\RatepayToMoneyInterface;
15
16
class BasketItemMapper extends BaseMapper
17
{
18
    /**
19
     * @var \Generated\Shared\Transfer\ItemTransfer
20
     */
21
    protected $itemTransfer;
22
23
    /**
24
     * @var \Generated\Shared\Transfer\RatepayRequestTransfer
25
     */
26
    protected $requestTransfer;
27
28
    /**
29
     * @var \SprykerEco\Zed\Ratepay\Dependency\Facade\RatepayToMoneyInterface
30
     */
31
    protected $moneyFacade;
32
33
    /**
34
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
35
     * @param \Generated\Shared\Transfer\RatepayRequestTransfer $requestTransfer
36
     * @param \SprykerEco\Zed\Ratepay\Dependency\Facade\RatepayToMoneyInterface $moneyFacade
37
     */
38
    public function __construct(
39
        ItemTransfer $itemTransfer,
40
        RatepayRequestTransfer $requestTransfer,
41
        RatepayToMoneyInterface $moneyFacade
42
    ) {
43
        $this->itemTransfer = $itemTransfer;
44
        $this->requestTransfer = $requestTransfer;
45
        $this->moneyFacade = $moneyFacade;
46
    }
47
48
    /**
49
     * @return void
50
     */
51
    public function map()
52
    {
53
        $itemPrice = $this->itemTransfer->requireUnitGrossPrice()->getUnitPriceToPayAggregation();
54
        $itemPrice = $this->moneyFacade->convertIntegerToDecimal((int)$itemPrice);
55
56
        $itemTransfer = (new RatepayRequestShoppingBasketItemTransfer())
57
            ->setItemName($this->itemTransfer->requireName()->getName())
58
            ->setArticleNumber($this->itemTransfer->requireSku()->getSku())
59
            ->setUniqueArticleNumber($this->itemTransfer->requireGroupKey()->getGroupKey())
60
            ->setQuantity($this->itemTransfer->requireQuantity()->getQuantity())
61
            ->setTaxRate($this->itemTransfer->requireTaxRate()->getTaxRate())
62
            ->setDescription($this->itemTransfer->getDescription())
63
            ->setDescriptionAddition($this->itemTransfer->getDescriptionAddition())
64
            ->setUnitPriceGross($itemPrice);
65
66
        $productOptions = [];
67
        foreach ($this->itemTransfer->getProductOptions() as $productOption) {
68
            $productOptions[] = $productOption->getValue();
69
        }
70
71
        $itemTransfer->setProductOptions($productOptions);
72
73
        $this->initBasketIfEmpty();
74
        $this->requestTransfer->getShoppingBasket()->addItems($itemTransfer);
75
    }
76
77
    /**
78
     * @return float
79
     */
80
    protected function getBasketItemDiscount()
81
    {
82
        $itemDiscount = $this->itemTransfer->getUnitTotalDiscountAmountWithProductOption();
83
        $itemDiscount = $this->moneyFacade->convertIntegerToDecimal((int)$itemDiscount);
84
85
        return $itemDiscount;
86
    }
87
88
    /**
89
     * @return void
90
     */
91
    protected function initBasketIfEmpty()
92
    {
93
        if (!$this->requestTransfer->getShoppingBasket()) {
94
            $this->requestTransfer->setShoppingBasket(new RatepayRequestShoppingBasketTransfer());
95
        }
96
    }
97
}
98