PartialBasketMapper::initBasketIfEmpty()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
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\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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 Spryker\Shared\Kernel\Transfer\TransferInterface;
14
use SprykerEco\Zed\Ratepay\Dependency\Facade\RatepayToMoneyInterface;
15
16
class PartialBasketMapper extends BaseMapper
17
{
18
    /**
19
     * @var \Generated\Shared\Transfer\OrderTransfer
20
     */
21
    protected $orderTransfer;
22
23
    /**
24
     * @var \Generated\Shared\Transfer\OrderTransfer
25
     */
26
    protected $partialOrderTransfer;
27
28
    /**
29
     * @var \Generated\Shared\Transfer\RatepayPaymentElvTransfer|\Generated\Shared\Transfer\RatepayPaymentInstallmentTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...tepayPaymentElvTransfer 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...
Bug introduced by
The type Generated\Shared\Transfe...mentInstallmentTransfer 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...
30
     */
31
    protected $ratepayPaymentTransfer;
32
33
    /**
34
     * @var bool
35
     */
36
    protected $needToSendShipping;
37
38
    /**
39
     * @var float
40
     */
41
    protected $discountTaxRate;
42
43
    /**
44
     * @var \Generated\Shared\Transfer\RatepayRequestTransfer
45
     */
46
    protected $requestTransfer;
47
48
    /**
49
     * @var \SprykerEco\Zed\Ratepay\Dependency\Facade\RatepayToMoneyInterface
50
     */
51
    protected $moneyFacade;
52
53
    /**
54
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
55
     * @param \Generated\Shared\Transfer\OrderTransfer $partialOrderTransfer
56
     * @param \Spryker\Shared\Kernel\Transfer\TransferInterface $ratepayPaymentTransfer
57
     * @param bool $needToSendShipping
58
     * @param float $discountTaxRate
59
     * @param \Generated\Shared\Transfer\RatepayRequestTransfer $requestTransfer
60
     * @param \SprykerEco\Zed\Ratepay\Dependency\Facade\RatepayToMoneyInterface $moneyFacade
61
     */
62
    public function __construct(
63
        OrderTransfer $orderTransfer,
64
        OrderTransfer $partialOrderTransfer,
65
        TransferInterface $ratepayPaymentTransfer,
66
        $needToSendShipping,
67
        $discountTaxRate,
68
        RatepayRequestTransfer $requestTransfer,
69
        RatepayToMoneyInterface $moneyFacade
70
    ) {
71
        $this->orderTransfer = $orderTransfer;
72
        $this->partialOrderTransfer = $partialOrderTransfer;
73
        $this->ratepayPaymentTransfer = $ratepayPaymentTransfer;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ratepayPaymentTransfer of type Spryker\Shared\Kernel\Transfer\TransferInterface is incompatible with the declared type Generated\Shared\Transfe...mentInstallmentTransfer of property $ratepayPaymentTransfer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
74
        $this->needToSendShipping = $needToSendShipping;
75
        $this->discountTaxRate = $discountTaxRate;
76
        $this->requestTransfer = $requestTransfer;
77
        $this->moneyFacade = $moneyFacade;
78
    }
79
80
    /**
81
     * @return void
82
     */
83
    public function map()
84
    {
85
        $partialOrderTotals = $this->partialOrderTransfer->getTotals();
86
87
        $this->initBasketIfEmpty();
88
        $shoppingBasket = $this->requestTransfer->getShoppingBasket();
89
        $shoppingBasket
90
            ->setCurrency($this->ratepayPaymentTransfer->requireCurrencyIso3()->getCurrencyIso3())
91
            ->setDiscountTitle(BasketMapper::DEFAULT_DISCOUNT_NODE_VALUE)
92
            ->setDiscountUnitPrice($this->moneyFacade->convertIntegerToDecimal((int)$partialOrderTotals->getDiscountTotal()) * BasketMapper::BASKET_DISCOUNT_COEFFICIENT)
93
            ->setDiscountTaxRate($this->discountTaxRate);
94
95
        $grandTotal = $partialOrderTotals->getGrandTotal();
96
97
        if ($this->needToSendShipping) {
98
            $totalsTransfer = $this->orderTransfer->requireTotals()->getTotals();
99
            $shippingUnitPrice = $totalsTransfer->requireExpenseTotal()->getExpenseTotal();
100
            $grandTotal += $shippingUnitPrice;
101
102
            $shoppingBasket
103
                ->setShippingUnitPrice($this->moneyFacade->convertIntegerToDecimal((int)$shippingUnitPrice))
104
                ->setShippingTitle(BasketMapper::DEFAULT_SHIPPING_NODE_VALUE)
105
                ->setShippingTaxRate(BasketMapper::DEFAULT_SHIPPING_TAX_RATE);
106
        }
107
        $shoppingBasket->setAmount($this->moneyFacade->convertIntegerToDecimal((int)$grandTotal));
108
109
        if (count($this->orderTransfer->getExpenses())) {
110
            $this->requestTransfer->getShoppingBasket()
111
                ->setShippingTaxRate($this->orderTransfer->getExpenses()[0]->getTaxRate());
112
        }
113
    }
114
115
    /**
116
     * @return void
117
     */
118
    protected function initBasketIfEmpty()
119
    {
120
        if (!$this->requestTransfer->getShoppingBasket()) {
121
            $this->requestTransfer->setShoppingBasket(new RatepayRequestShoppingBasketTransfer());
122
        }
123
    }
124
}
125