CustomerMapper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
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\Ratepay\Business\Api\Mapper;
9
10
use Generated\Shared\Transfer\RatepayPaymentRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...yPaymentRequestTransfer 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\RatepayRequestCustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...RequestCustomerTransfer 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 SprykerEco\Zed\Ratepay\Business\Api\Constants as ApiConstants;
13
14
class CustomerMapper extends BaseMapper
15
{
16
    public const ALLOW_CREDIT_INQUIRY_YES = 'yes';
17
    public const ALLOW_CREDIT_INQUIRY_NO = 'no';
18
19
    /**
20
     * @var \Generated\Shared\Transfer\RatepayPaymentRequestTransfer
21
     */
22
    protected $ratepayPaymentRequestTransfer;
23
24
    /**
25
     * @var \Generated\Shared\Transfer\RatepayRequestTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RatepayRequestTransfer 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...
26
     */
27
    protected $requestTransfer;
28
29
    /**
30
     * @param \Generated\Shared\Transfer\RatepayPaymentRequestTransfer $ratepayPaymentRequestTransfer
31
     * @param \Generated\Shared\Transfer\RatepayRequestTransfer $requestTransfer
32
     */
33
    public function __construct(
34
        RatepayPaymentRequestTransfer $ratepayPaymentRequestTransfer,
35
        $requestTransfer
36
    ) {
37
38
        $this->ratepayPaymentRequestTransfer = $ratepayPaymentRequestTransfer;
39
        $this->requestTransfer = $requestTransfer;
40
    }
41
42
    /**
43
     * @return void
44
     */
45
    public function map()
46
    {
47
        $billingAddress = $this->ratepayPaymentRequestTransfer->requireBillingAddress()->getBillingAddress();
48
        $shippingAddress = $this->ratepayPaymentRequestTransfer->requireBillingAddress()->getShippingAddress();
49
50
        $this->requestTransfer->setCustomer(new RatepayRequestCustomerTransfer())->getCustomer()
51
            ->setAllowCreditInquiry($this->prepareAllowCreditInquiry())
52
            ->setGender($this->ratepayPaymentRequestTransfer->requireGender()->getGender())
53
            ->setDob($this->ratepayPaymentRequestTransfer->requireDateOfBirth()->getDateOfBirth())
54
            ->setIpAddress($this->ratepayPaymentRequestTransfer->requireIpAddress()->getIpAddress())
55
            ->setFirstName($billingAddress->getFirstName())
56
            ->setLastName($billingAddress->getLastName())
57
            ->setCompany($billingAddress->getCompany())
58
            ->setEmail($this->ratepayPaymentRequestTransfer->requireCustomerEmail()->getCustomerEmail())
59
            ->setPhone($this->ratepayPaymentRequestTransfer->requireCustomerPhone()->getCustomerPhone());
60
61
        $addressMapper = new AddressMapper(
62
            $billingAddress,
63
            ApiConstants::REQUEST_MODEL_ADDRESS_TYPE_BILLING,
64
            $this->requestTransfer
65
        );
66
        $addressMapper->map();
67
68
        $addressMapper = new AddressMapper(
69
            $shippingAddress,
70
            ApiConstants::REQUEST_MODEL_ADDRESS_TYPE_DELIVERY,
71
            $this->requestTransfer
72
        );
73
        $addressMapper->map();
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    protected function prepareAllowCreditInquiry()
80
    {
81
        return ($this->ratepayPaymentRequestTransfer->getCustomerAllowCreditInquiry() === false)
82
            ? self::ALLOW_CREDIT_INQUIRY_NO : self::ALLOW_CREDIT_INQUIRY_YES;
83
    }
84
}
85