Completed
Push — feature/eco-3656/eco-3658-enab... ( 39446b...85b20e )
by
unknown
05:26
created

PayPalExpressToQuoteMapper::mapCustomerTransfer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 16
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace SprykerEco\Yves\Computop\Mapper\Init\PrePlace;
4
5
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...
6
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...
7
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...
8
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...
9
10
class PayPalExpressToQuoteMapper implements PayPalExpressToQuoteMapperInterface
11
{
12
    /**
13
     * @param QuoteTransfer $quoteTransfer
14
     * @param ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
15
     *
16
     * @return QuoteTransfer
17
     */
18
    public function mapAddressTransfer(
19
        QuoteTransfer $quoteTransfer,
20
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
21
    ): QuoteTransfer
22
    {
23
        $shippingAddressTransfer = new AddressTransfer();
24
        $shippingAddressTransfer->setFirstName($computopPayPalExpressInitResponseTransfer->getFirstName());
25
        $shippingAddressTransfer->setLastName($computopPayPalExpressInitResponseTransfer->getLastName());
26
        $shippingAddressTransfer->setAddress1($computopPayPalExpressInitResponseTransfer->getAddressStreet());
27
        $shippingAddressTransfer->setAddress2($computopPayPalExpressInitResponseTransfer->getAddressStreet2());
28
        $shippingAddressTransfer->setCity($computopPayPalExpressInitResponseTransfer->getAddressCity());
29
        $shippingAddressTransfer->setState($computopPayPalExpressInitResponseTransfer->getAddressState());
30
        $shippingAddressTransfer->setZipCode($computopPayPalExpressInitResponseTransfer->getAddressZip());
31
        $shippingAddressTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getAddressCountryCode());
32
        $shippingAddressTransfer->setPhone($computopPayPalExpressInitResponseTransfer->getPhone());
33
34
        foreach ($quoteTransfer->getItems() as $item) {
35
            $item->getShipment()->setShippingAddress($shippingAddressTransfer);
36
        }
37
38
        foreach ($quoteTransfer->getExpenses() as $expense) {
39
            $expense->getShipment()->setShippingAddress($shippingAddressTransfer);
40
        }
41
42
        $quoteTransfer->setShippingAddress($shippingAddressTransfer);
43
44
        return $quoteTransfer;
45
    }
46
47
    /**
48
     * @param QuoteTransfer $quoteTransfer
49
     * @param ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
50
     *
51
     * @return QuoteTransfer
52
     */
53
    public function mapBillingTransfer(
54
        QuoteTransfer $quoteTransfer,
55
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
56
    ): QuoteTransfer
57
    {
58
        $billingAddressTransfer = new AddressTransfer();
59
        $billingAddressTransfer->setFirstName($computopPayPalExpressInitResponseTransfer->getFirstName());
60
        $billingAddressTransfer->setLastName($computopPayPalExpressInitResponseTransfer->getLastName());
61
        $billingAddressTransfer->setAddress1($computopPayPalExpressInitResponseTransfer->getBillingAddressStreet());
62
        $billingAddressTransfer->setAddress2($computopPayPalExpressInitResponseTransfer->getBillingAddressStreet2());
63
        $billingAddressTransfer->setCity($computopPayPalExpressInitResponseTransfer->getBillingAddressCity());
64
        $billingAddressTransfer->setState($computopPayPalExpressInitResponseTransfer->getBillingAddressState());
65
        $billingAddressTransfer->setIso2Code($computopPayPalExpressInitResponseTransfer->getBillingAddressCountryCode());
66
        $billingAddressTransfer->setFirstName($computopPayPalExpressInitResponseTransfer->getBillingName());
67
        $quoteTransfer->setBillingAddress($billingAddressTransfer);
68
69
        return $quoteTransfer;
70
    }
71
72
    /**
73
     * @param QuoteTransfer $quoteTransfer
74
     * @param ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
75
     *
76
     * @return QuoteTransfer
77
     */
78
    public function mapCustomerTransfer(
79
        QuoteTransfer $quoteTransfer,
80
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
81
    ): QuoteTransfer
82
    {
83
        $customerTransfer = new CustomerTransfer();
84
85
        $customerTransfer->setFirstName($computopPayPalExpressInitResponseTransfer->getFirstName());
86
        $customerTransfer->setLastName($computopPayPalExpressInitResponseTransfer->getLastName());
87
        $customerTransfer->setEmail($computopPayPalExpressInitResponseTransfer->getEmail());
88
        $customerTransfer->setIsGuest(true);
89
        $quoteTransfer->setAcceptTermsAndConditions(true);
90
91
        $quoteTransfer->setCustomer($customerTransfer);
92
93
        return $quoteTransfer;
94
    }
95
}
96