Completed
Pull Request — master (#14)
by Aleksey
20:12
created

convertDeliveryCustomer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 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\ArvatoRss\Business\Api\Converter;
9
10
use Generated\Shared\Transfer\ArvatoRssCustomerAddressTransfer;
11
use Generated\Shared\Transfer\ArvatoRssRiskCheckRequestTransfer;
12
use SprykerEco\Zed\ArvatoRss\Business\Api\ArvatoRssRequestApiConfig;
13
14
class RiskCheckRequestConverter implements RiskCheckRequestConverterInterface
15
{
16
    /**
17
     * @param \Generated\Shared\Transfer\ArvatoRssRiskCheckRequestTransfer $arvatoRssRiskCheckRequestTransfer
18
     *
19
     * @return array
20
     */
21
    public function convert(ArvatoRssRiskCheckRequestTransfer $arvatoRssRiskCheckRequestTransfer)
22
    {
23
        $billingCustomer = $this->convertBillingCustomer($arvatoRssRiskCheckRequestTransfer);
24
        $deliveryCustomer = $this->convertDeliveryCustomer($arvatoRssRiskCheckRequestTransfer);
25
        $order = $this->convertOrder($arvatoRssRiskCheckRequestTransfer);
26
27
        return $billingCustomer + $deliveryCustomer + $order;
28
    }
29
30
    /**
31
     * @param \Generated\Shared\Transfer\ArvatoRssRiskCheckRequestTransfer $arvatoRssRiskCheckRequestTransfer
32
     *
33
     * @return array
34
     */
35 View Code Duplication
    protected function convertBillingCustomer(ArvatoRssRiskCheckRequestTransfer $arvatoRssRiskCheckRequestTransfer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $result = [];
38
        $billingCustomerTransfer = $arvatoRssRiskCheckRequestTransfer->getBillingCustomer();
39
        $customerAddressTransfer = $billingCustomerTransfer->getAddress();
40
        $result[ArvatoRssRequestApiConfig::ARVATORSS_API_BILLINGCUSTOMER] = [
41
            ArvatoRssRequestApiConfig::ARVATORSS_API_FIRSTNAME => $billingCustomerTransfer->getFirstName(),
42
            ArvatoRssRequestApiConfig::ARVATORSS_API_LASTNAME => $billingCustomerTransfer->getLastName(),
43
            ArvatoRssRequestApiConfig::ARVATORSS_API_ADDRESS => $this->convertCustomerAddress($customerAddressTransfer),
44
        ];
45
46
        return $result;
47
    }
48
49
    /**
50
     * @param \Generated\Shared\Transfer\ArvatoRssRiskCheckRequestTransfer $arvatoRssRiskCheckRequestTransfer
51
     *
52
     * @return array
53
     */
54 View Code Duplication
    protected function convertDeliveryCustomer(ArvatoRssRiskCheckRequestTransfer $arvatoRssRiskCheckRequestTransfer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $result = [];
57
        $deliveryCustomerTransfer = $arvatoRssRiskCheckRequestTransfer->getDeliveryCustomer();
58
        $customerAddressTransfer = $deliveryCustomerTransfer->getAddress();
59
        $result[ArvatoRssRequestApiConfig::ARVATORSS_API_DELIVERYCUSTOMER] = [
60
            ArvatoRssRequestApiConfig::ARVATORSS_API_FIRSTNAME => $deliveryCustomerTransfer->getFirstName(),
61
            ArvatoRssRequestApiConfig::ARVATORSS_API_LASTNAME => $deliveryCustomerTransfer->getLastName(),
62
            ArvatoRssRequestApiConfig::ARVATORSS_API_ADDRESS => $this->convertCustomerAddress($customerAddressTransfer),
63
        ];
64
65
        return $result;
66
    }
67
68
    /**
69
     * @param \Generated\Shared\Transfer\ArvatoRssCustomerAddressTransfer $customerAddressTransfer
70
     *
71
     * @return array
72
     */
73
    protected function convertCustomerAddress(ArvatoRssCustomerAddressTransfer $customerAddressTransfer)
74
    {
75
        return [
76
            ArvatoRssRequestApiConfig::ARVATORSS_API_COUNTRY => $customerAddressTransfer->getCountry(),
77
            ArvatoRssRequestApiConfig::ARVATORSS_API_CITY => $customerAddressTransfer->getCity(),
78
            ArvatoRssRequestApiConfig::ARVATORSS_API_STREET => $customerAddressTransfer->getStreet(),
79
            ArvatoRssRequestApiConfig::ARVATORSS_API_STREET_NUMBER => $customerAddressTransfer->getStreetNumber(),
80
            ArvatoRssRequestApiConfig::ARVATORSS_API_ZIPCODE => $customerAddressTransfer->getZipCode(),
81
        ];
82
    }
83
84
    /**
85
     * @param \Generated\Shared\Transfer\ArvatoRssRiskCheckRequestTransfer $arvatoRssRiskCheckRequestTransfer
86
     *
87
     * @return array
88
     */
89
    protected function convertOrder(ArvatoRssRiskCheckRequestTransfer $arvatoRssRiskCheckRequestTransfer)
90
    {
91
        $result = [];
92
        $order = $arvatoRssRiskCheckRequestTransfer->getOrder();
93
94
        $result[ArvatoRssRequestApiConfig::ARVATORSS_API_ORDER] = [
95
            ArvatoRssRequestApiConfig::ARVATORSS_API_REGISTEREDORDER => $order->getRegisteredOrder(),
96
            ArvatoRssRequestApiConfig::ARVATORSS_API_CURRENCY => $order->getCurrency(),
97
            ArvatoRssRequestApiConfig::ARVATORSS_API_GROSSTOTALBILL => $order->getGrossTotalBill(),
98
            ArvatoRssRequestApiConfig::ARVATORSS_API_TOTALORDERVALUE => $order->getTotalOrderValue(),
99
        ];
100
        $result[ArvatoRssRequestApiConfig::ARVATORSS_API_ORDER][ArvatoRssRequestApiConfig::ARVATORSS_API_ITEM] = [];
101
102 View Code Duplication
        foreach ($order->getItems() as $item) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
            $result[ArvatoRssRequestApiConfig::ARVATORSS_API_ORDER][ArvatoRssRequestApiConfig::ARVATORSS_API_ITEM][] = [
104
                ArvatoRssRequestApiConfig::ARVATORSS_API_PRODUCTNUMBER => $item->getProductNumber(),
105
                ArvatoRssRequestApiConfig::ARVATORSS_API_PRODUCTGROUPID => $item->getProductGroupId(),
106
                ArvatoRssRequestApiConfig::ARVATORSS_API_UNITPRICE => $item->getUnitPrice(),
107
                ArvatoRssRequestApiConfig::ARVATORSS_API_UNITCOUNT => $item->getUnitCount(),
108
            ];
109
        }
110
111
        return $result;
112
    }
113
}
114