ShoppingBasket::buildData()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 18
c 1
b 0
f 0
nc 8
nop 0
dl 0
loc 30
rs 9.6666
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\Builder;
9
10
class ShoppingBasket extends AbstractBuilder implements ShoppingBasketInterface
11
{
12
    public const ROOT_TAG = 'shopping-basket';
13
14
    /**
15
     * @return array
16
     */
17
    public function buildData()
18
    {
19
        $return = [
20
            '@amount' => $this->requestTransfer->getShoppingBasket()->getAmount(),
21
            '@currency' => $this->requestTransfer->getShoppingBasket()->getCurrency(),
22
            'items' => [],
23
        ];
24
25
        if ($this->requestTransfer->getShoppingBasket()->getShippingUnitPrice()) {
26
            $return['shipping'] = [
27
                '@unit-price-gross' => $this->requestTransfer->getShoppingBasket()->getShippingUnitPrice(),
28
                '@tax-rate' => $this->requestTransfer->getShoppingBasket()->getShippingTaxRate(),
29
                '#' => $this->requestTransfer->getShoppingBasket()->getShippingTitle(),
30
            ];
31
        }
32
33
        if ($this->requestTransfer->getShoppingBasket()->getDiscountUnitPrice()) {
34
            $return['discount'] = [
35
                '@unit-price-gross' => $this->requestTransfer->getShoppingBasket()->getDiscountUnitPrice(),
36
                '@tax-rate' => $this->requestTransfer->getShoppingBasket()->getDiscountTaxRate(),
37
                '#' => $this->requestTransfer->getShoppingBasket()->getDiscountTitle(),
38
            ];
39
        }
40
41
        $items = $this->requestTransfer->getShoppingBasket()->getItems()->getArrayCopy();
42
        foreach (array_keys($items) as $itemNumber) {
43
            $return['items'][] = (new ShoppingBasketItem($this->requestTransfer, $itemNumber));
44
        }
45
46
        return $return;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getRootTag()
53
    {
54
        return static::ROOT_TAG;
55
    }
56
}
57