Passed
Push — feature/eco-3656/eco-3658-enab... ( 4d2e5e...c70d81 )
by
unknown
06:33
created

mapShippingAddressToQuoteItems()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
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\Yves\Computop\Mapper\Init\PrePlace;
9
10
use Generated\Shared\Transfer\AddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AddressTransfer 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\ComputopPayPalExpressInitResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...essInitResponseTransfer 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\CountryTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CountryTransfer 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\CustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CustomerTransfer 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 Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer 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...
15
16
class PayPalExpressToQuoteMapper implements PayPalExpressToQuoteMapperInterface
17
{
18
    /**
19
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
20
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
21
     *
22
     * @return \Generated\Shared\Transfer\QuoteTransfer
23
     */
24
    public function mapAddressFromComputopPayPalExpressInitResponseToQuote(
25
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer,
26
        QuoteTransfer $quoteTransfer
27
    ): QuoteTransfer {
28
        $countryTransfer = new CountryTransfer();
29
        $countryTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getAddressCountryCode());
30
31
        $shippingAddressTransfer = new AddressTransfer();
32
        $shippingAddressTransfer->fromArray($computopPayPalExpressInitResponseTransfer->toArray(), true);
33
        $shippingAddressTransfer->setAddress1($computopPayPalExpressInitResponseTransfer->getAddressStreet());
34
        $shippingAddressTransfer->setAddress2($computopPayPalExpressInitResponseTransfer->getAddressStreet2());
35
        $shippingAddressTransfer->setCity($computopPayPalExpressInitResponseTransfer->getAddressCity());
36
        $shippingAddressTransfer->setState($computopPayPalExpressInitResponseTransfer->getAddressState());
37
        $shippingAddressTransfer->setZipCode($computopPayPalExpressInitResponseTransfer->getAddressZip());
38
        $shippingAddressTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getAddressCountryCode());
39
        $shippingAddressTransfer->setCountry($countryTransfer);
40
41
        $this->mapShippingAddressToQuoteItems($shippingAddressTransfer, $quoteTransfer);
42
        $this->mapShippingAddressToQuoteExpenses($shippingAddressTransfer, $quoteTransfer);
43
44
        $quoteTransfer->setShippingAddress($shippingAddressTransfer);
45
46
        return $quoteTransfer;
47
    }
48
49
    /**
50
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
51
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
52
     *
53
     * @return \Generated\Shared\Transfer\QuoteTransfer
54
     */
55
    public function mapBillingAddressFromComputopPayPalExpressInitResponseToQuote(
56
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer,
57
        QuoteTransfer $quoteTransfer
58
    ): QuoteTransfer {
59
        $countryTransfer = new CountryTransfer();
60
        $countryTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getAddressCountryCode());
61
62
        $billingAddressTransfer = new AddressTransfer();
63
        $billingAddressTransfer->fromArray($computopPayPalExpressInitResponseTransfer->toArray(), true);
64
        $billingAddressTransfer->setAddress1($computopPayPalExpressInitResponseTransfer->getBillingAddressStreet());
65
        $billingAddressTransfer->setAddress2($computopPayPalExpressInitResponseTransfer->getBillingAddressStreet2());
66
        $billingAddressTransfer->setZipCode($computopPayPalExpressInitResponseTransfer->getBillingAddressZip());
67
        $billingAddressTransfer->setCity($computopPayPalExpressInitResponseTransfer->getBillingAddressCity());
68
        $billingAddressTransfer->setState($computopPayPalExpressInitResponseTransfer->getBillingAddressState());
69
        $billingAddressTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getBillingAddressCountryCode());
70
        $billingAddressTransfer->setCountry($countryTransfer);
71
        $billingAddressTransfer->setFirstName($computopPayPalExpressInitResponseTransfer->getBillingName());
72
        $billingAddressTransfer->setLastName($computopPayPalExpressInitResponseTransfer->getLastName());
73
74
        $quoteTransfer->setBillingAddress($billingAddressTransfer);
75
76
        return $quoteTransfer;
77
    }
78
79
    /**
80
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
81
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
82
     *
83
     * @return \Generated\Shared\Transfer\QuoteTransfer
84
     */
85
    public function mapCustomerFromComputopPayPalExpressInitResponseToQuote(
86
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer,
87
        QuoteTransfer $quoteTransfer
88
    ): QuoteTransfer {
89
        $customerTransfer = new CustomerTransfer();
90
        $customerTransfer->fromArray($computopPayPalExpressInitResponseTransfer->toArray(), true);
91
        $customerTransfer->setIsGuest(true);
92
        $quoteTransfer->setAcceptTermsAndConditions(true);
93
        $quoteTransfer->setCustomer($customerTransfer);
94
95
        return $quoteTransfer;
96
    }
97
98
    /**
99
     * @param \Generated\Shared\Transfer\AddressTransfer $shippingAddressTransfer
100
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
101
     *
102
     * @return \Generated\Shared\Transfer\QuoteTransfer
103
     */
104
    protected function mapShippingAddressToQuoteItems(AddressTransfer $shippingAddressTransfer, QuoteTransfer $quoteTransfer): QuoteTransfer
105
    {
106
        foreach ($quoteTransfer->getItems() as $itemTransfer) {
107
            $itemTransfer->getShipment()->setShippingAddress($shippingAddressTransfer);
108
        }
109
110
        return $quoteTransfer;
111
    }
112
113
    /**
114
     * @param \Generated\Shared\Transfer\AddressTransfer $shippingAddressTransfer
115
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
116
     *
117
     * @return \Generated\Shared\Transfer\QuoteTransfer
118
     */
119
    protected function mapShippingAddressToQuoteExpenses(AddressTransfer $shippingAddressTransfer, QuoteTransfer $quoteTransfer): QuoteTransfer
120
    {
121
        foreach ($quoteTransfer->getExpenses() as $expenseTransfer) {
122
            $expenseTransfer->getShipment()->setShippingAddress($shippingAddressTransfer);
123
        }
124
125
        return $quoteTransfer;
126
    }
127
}
128