Passed
Pull Request — feature/eco-3656/dev-paypal-ex... (#40)
by
unknown
10:59 queued 05:38
created

mapAddressFromComputopPayPalExpressInitResponseToQuote()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 28
rs 9.7
cc 3
nc 4
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
        foreach ($quoteTransfer->getItems() as $itemTransfer) {
42
            $itemTransfer->getShipment()->setShippingAddress($shippingAddressTransfer);
43
        }
44
45
        foreach ($quoteTransfer->getExpenses() as $expenseTransfer) {
46
            $expenseTransfer->getShipment()->setShippingAddress($shippingAddressTransfer);
47
        }
48
49
        $quoteTransfer->setShippingAddress($shippingAddressTransfer);
50
51
        return $quoteTransfer;
52
    }
53
54
    /**
55
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
56
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
57
     *
58
     * @return \Generated\Shared\Transfer\QuoteTransfer
59
     */
60
    public function mapBillingAddressFromComputopPayPalExpressInitResponseToQuote(
61
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer,
62
        QuoteTransfer $quoteTransfer
63
    ): QuoteTransfer {
64
        $countryTransfer = new CountryTransfer();
65
        $countryTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getAddressCountryCode());
66
67
        $billingAddressTransfer = new AddressTransfer();
68
        $billingAddressTransfer->fromArray($computopPayPalExpressInitResponseTransfer->toArray(), true);
69
        $billingAddressTransfer->setAddress1($computopPayPalExpressInitResponseTransfer->getBillingAddressStreet());
70
        $billingAddressTransfer->setAddress2($computopPayPalExpressInitResponseTransfer->getBillingAddressStreet2());
71
        $billingAddressTransfer->setZipCode($computopPayPalExpressInitResponseTransfer->getBillingAddressZip());
72
        $billingAddressTransfer->setCity($computopPayPalExpressInitResponseTransfer->getBillingAddressCity());
73
        $billingAddressTransfer->setState($computopPayPalExpressInitResponseTransfer->getBillingAddressState());
74
        $billingAddressTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getBillingAddressCountryCode());
75
        $billingAddressTransfer->setCountry($countryTransfer);
76
        $billingAddressTransfer->setFirstName($computopPayPalExpressInitResponseTransfer->getBillingName());
77
        $billingAddressTransfer->setLastName($computopPayPalExpressInitResponseTransfer->getLastName());
78
79
        $quoteTransfer->setBillingAddress($billingAddressTransfer);
80
81
        return $quoteTransfer;
82
    }
83
84
    /**
85
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
86
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
87
     *
88
     * @return \Generated\Shared\Transfer\QuoteTransfer
89
     */
90
    public function mapCustomerFromComputopPayPalExpressInitResponseToQuote(
91
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer,
92
        QuoteTransfer $quoteTransfer
93
    ): QuoteTransfer {
94
        $customerTransfer = new CustomerTransfer();
95
        $customerTransfer->fromArray($computopPayPalExpressInitResponseTransfer->toArray(), true);
96
        $customerTransfer->setIsGuest(true);
97
        $quoteTransfer->setAcceptTermsAndConditions(true);
98
        $quoteTransfer->setCustomer($customerTransfer);
99
100
        return $quoteTransfer;
101
    }
102
}
103