Address   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildData() 0 26 4
A getRootTag() 0 3 1
A __construct() 0 5 1
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\Builder;
9
10
use 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...
11
use SprykerEco\Zed\Ratepay\Business\Api\Constants;
12
13
class Address extends AbstractBuilder implements AddressInterface
14
{
15
    public const ROOT_TAG = 'address';
16
17
    /**
18
     * @var string
19
     */
20
    protected $addressType;
21
22
    /**
23
     * @param \Generated\Shared\Transfer\RatepayRequestTransfer $requestTransfer
24
     * @param string $addressType
25
     */
26
    public function __construct(RatepayRequestTransfer $requestTransfer, $addressType)
27
    {
28
        parent::__construct($requestTransfer);
29
30
        $this->addressType = $addressType;
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    public function buildData()
37
    {
38
        $addressTransfer = ($this->addressType == Constants::REQUEST_MODEL_ADDRESS_TYPE_BILLING)
39
            ? $this->requestTransfer->getBillingAddress()
40
            : $this->requestTransfer->getShippingAddress();
41
42
        $result = ['@type' => $this->addressType];
43
        if ($addressTransfer->getFirstName() !== null) {
44
            $result['first-name'] = $addressTransfer->getFirstName();
45
        }
46
        if ($addressTransfer->getLastName() !== null) {
47
            $result['last-name'] = $addressTransfer->getLastName();
48
        }
49
        $result = array_merge(
50
            $result,
51
            [
52
                'street' => $addressTransfer->getStreet(),
53
                'street-additional' => $addressTransfer->getStreetAdditional(),
54
                'street-number' => $addressTransfer->getStreetNumber(),
55
                'zip-code' => $addressTransfer->getZipCode(),
56
                'city' => $addressTransfer->getCity(),
57
                'country-code' => $addressTransfer->getCountryCode(),
58
            ]
59
        );
60
61
        return $result;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getRootTag()
68
    {
69
        return static::ROOT_TAG;
70
    }
71
}
72