BasketMapper   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 62
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A map() 0 18 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\RatepayPaymentRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...yPaymentRequestTransfer 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\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...
12
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...
13
use SprykerEco\Zed\Ratepay\Dependency\Facade\RatepayToMoneyInterface;
14
15
class BasketMapper extends BaseMapper
16
{
17
    public const DEFAULT_DISCOUNT_NODE_VALUE = 'Discount';
18
    public const DEFAULT_DISCOUNT_TAX_RATE = 0;
19
    public const DEFAULT_DISCOUNT_UNIT_PRICE = 0;
20
21
    public const DEFAULT_SHIPPING_NODE_VALUE = 'Shipping costs';
22
    public const DEFAULT_SHIPPING_TAX_RATE = 0;
23
24
    public const BASKET_DISCOUNT_COEFFICIENT = -1;
25
26
    /**
27
     * @var \Generated\Shared\Transfer\RatepayPaymentRequestTransfer
28
     */
29
    protected $ratepayPaymentRequestTransfer;
30
31
    /**
32
     * @var \Generated\Shared\Transfer\RatepayRequestTransfer
33
     */
34
    protected $requestTransfer;
35
36
    /**
37
     * @var \SprykerEco\Zed\Ratepay\Dependency\Facade\RatepayToMoneyInterface
38
     */
39
    protected $moneyFacade;
40
41
    /**
42
     * @param \Generated\Shared\Transfer\RatepayPaymentRequestTransfer $ratepayPaymentRequestTransfer
43
     * @param \Generated\Shared\Transfer\RatepayRequestTransfer $requestTransfer
44
     * @param \SprykerEco\Zed\Ratepay\Dependency\Facade\RatepayToMoneyInterface $moneyFacade
45
     */
46
    public function __construct(
47
        RatepayPaymentRequestTransfer $ratepayPaymentRequestTransfer,
48
        RatepayRequestTransfer $requestTransfer,
49
        RatepayToMoneyInterface $moneyFacade
50
    ) {
51
        $this->ratepayPaymentRequestTransfer = $ratepayPaymentRequestTransfer;
52
        $this->requestTransfer = $requestTransfer;
53
        $this->moneyFacade = $moneyFacade;
54
    }
55
56
    /**
57
     * @return void
58
     */
59
    public function map()
60
    {
61
        $shippingUnitPrice = $this->moneyFacade->convertIntegerToDecimal((int)$this->ratepayPaymentRequestTransfer->requireShippingExpenseTotal()->getShippingExpenseTotal());
62
        $grandTotal = $this->moneyFacade->convertIntegerToDecimal((int)$this->ratepayPaymentRequestTransfer->requireGrandTotal()->getGrandTotal());
63
        $discountTotal = $this->moneyFacade->convertIntegerToDecimal((int)$this->ratepayPaymentRequestTransfer->getDiscountTotal());
64
65
        $this->requestTransfer
66
            ->setShoppingBasket(new RatepayRequestShoppingBasketTransfer())->getShoppingBasket()
67
            ->setAmount($grandTotal)
68
            ->setCurrency($this->ratepayPaymentRequestTransfer->requireCurrencyIso3()->getCurrencyIso3())
69
70
            ->setShippingUnitPrice($shippingUnitPrice)
71
            ->setShippingTitle(self::DEFAULT_SHIPPING_NODE_VALUE)
72
            ->setShippingTaxRate($this->ratepayPaymentRequestTransfer->getShippingTaxRate())
73
74
            ->setDiscountTitle(self::DEFAULT_DISCOUNT_NODE_VALUE)
75
            ->setDiscountUnitPrice($discountTotal * self::BASKET_DISCOUNT_COEFFICIENT)
76
            ->setDiscountTaxRate($this->ratepayPaymentRequestTransfer->getDiscountTaxRate());
77
    }
78
}
79