Passed
Pull Request — feature/eco-3656/dev-paypal-ex... (#40)
by
unknown
07:17
created

PayPalExpressToQuoteMapper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 44
dl 0
loc 88
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mapCustomerTransfer() 0 13 1
A mapBillingTransfer() 0 22 1
A mapAddressTransfer() 0 29 3
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\QuoteTransfer $quoteTransfer
20
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
21
     *
22
     * @return \Generated\Shared\Transfer\QuoteTransfer
23
     */
24
    public function mapAddressTransfer(
25
        QuoteTransfer $quoteTransfer,
26
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
27
    ): QuoteTransfer {
28
        $shippingAddressTransfer = new AddressTransfer();
29
        $countryTransfer = new CountryTransfer();
30
        $countryTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getAddressCountryCode());
31
        $shippingAddressTransfer->setFirstName($computopPayPalExpressInitResponseTransfer->getFirstName());
32
        $shippingAddressTransfer->setLastName($computopPayPalExpressInitResponseTransfer->getLastName());
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
        $shippingAddressTransfer->setPhone($computopPayPalExpressInitResponseTransfer->getPhone());
41
42
        foreach ($quoteTransfer->getItems() as $itemTransfer) {
43
            $itemTransfer->getShipment()->setShippingAddress($shippingAddressTransfer);
44
        }
45
46
        foreach ($quoteTransfer->getExpenses() as $expenseTransfer) {
47
            $expenseTransfer->getShipment()->setShippingAddress($shippingAddressTransfer);
48
        }
49
50
        $quoteTransfer->setShippingAddress($shippingAddressTransfer);
51
52
        return $quoteTransfer;
53
    }
54
55
    /**
56
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
57
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
58
     *
59
     * @return \Generated\Shared\Transfer\QuoteTransfer
60
     */
61
    public function mapBillingTransfer(
62
        QuoteTransfer $quoteTransfer,
63
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
64
    ): QuoteTransfer {
65
        $billingAddressTransfer = new AddressTransfer();
66
        $countryTransfer = new CountryTransfer();
67
        $countryTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getAddressCountryCode());
68
        $billingAddressTransfer->setFirstName($computopPayPalExpressInitResponseTransfer->getFirstName());
69
        $billingAddressTransfer->setLastName($computopPayPalExpressInitResponseTransfer->getLastName());
70
        $billingAddressTransfer->setAddress1($computopPayPalExpressInitResponseTransfer->getBillingAddressStreet());
71
        $billingAddressTransfer->setAddress2($computopPayPalExpressInitResponseTransfer->getBillingAddressStreet2());
72
        $billingAddressTransfer->setZipCode($computopPayPalExpressInitResponseTransfer->getBillingAddressZip());
73
        $billingAddressTransfer->setCity($computopPayPalExpressInitResponseTransfer->getBillingAddressCity());
74
        $billingAddressTransfer->setState($computopPayPalExpressInitResponseTransfer->getBillingAddressState());
75
        $billingAddressTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getBillingAddressCountryCode());
76
        $billingAddressTransfer->setCountry($countryTransfer);
77
        $billingAddressTransfer->setFirstName($computopPayPalExpressInitResponseTransfer->getBillingName());
78
        $billingAddressTransfer->setLastName($computopPayPalExpressInitResponseTransfer->getLastName());
79
80
        $quoteTransfer->setBillingAddress($billingAddressTransfer);
81
82
        return $quoteTransfer;
83
    }
84
85
    /**
86
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
87
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
88
     *
89
     * @return \Generated\Shared\Transfer\QuoteTransfer
90
     */
91
    public function mapCustomerTransfer(
92
        QuoteTransfer $quoteTransfer,
93
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
94
    ): QuoteTransfer {
95
        $customerTransfer = new CustomerTransfer();
96
        $customerTransfer->setFirstName($computopPayPalExpressInitResponseTransfer->getFirstName());
97
        $customerTransfer->setLastName($computopPayPalExpressInitResponseTransfer->getLastName());
98
        $customerTransfer->setEmail($computopPayPalExpressInitResponseTransfer->getEmail());
99
        $customerTransfer->setIsGuest(true);
100
        $quoteTransfer->setAcceptTermsAndConditions(true);
101
        $quoteTransfer->setCustomer($customerTransfer);
102
103
        return $quoteTransfer;
104
    }
105
}
106