StructuredAddress::loadAddress()   D
last analyzed

Complexity

Conditions 10
Paths 512

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 4.2804
c 0
b 0
f 0
cc 10
nc 512
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\Struct\DocRefund\UpdateRefund;
24
25
use Amadeus\Client\RequestOptions\DocRefund\AddressOpt;
26
27
/**
28
 * StructuredAddress
29
 *
30
 * @package Amadeus\Client\Struct\DocRefund\UpdateRefund
31
 * @author Dieter Devlieghere <[email protected]>
32
 */
33
class StructuredAddress
34
{
35
    const TYPE_BILLING_ADDRESS = "AB";
36
37
    /**
38
     * self::TYPE_*
39
     *
40
     * @var string
41
     */
42
    public $informationType;
43
44
    /**
45
     * @var Address[]
46
     */
47
    public $address = [];
48
49
    /**
50
     * StructuredAddress constructor.
51
     *
52
     * @param AddressOpt $opt
53
     */
54
    public function __construct(AddressOpt $opt)
55
    {
56
        $this->informationType = $opt->type;
57
58
        $this->loadAddress($opt);
59
    }
60
61
    /**
62
     * @param AddressOpt $opt
63
     */
64
    protected function loadAddress($opt)
65
    {
66
        if (!empty($opt->company)) {
67
            $this->address[] = new Address(
68
                Address::OPTION_COMPANY,
69
                $opt->company
70
            );
71
        }
72
        if (!empty($opt->name)) {
73
            $this->address[] = new Address(
74
                Address::OPTION_NAME,
75
                $opt->name
76
            );
77
        }
78
        if (!empty($opt->addressLine1)) {
79
            $this->address[] = new Address(
80
                Address::OPTION_ADDRESS_LINE_1,
81
                $opt->addressLine1
82
            );
83
        }
84
        if (!empty($opt->addressLine2)) {
85
            $this->address[] = new Address(
86
                Address::OPTION_ADDRESS_LINE_2,
87
                $opt->addressLine2
88
            );
89
        }
90
        if (!empty($opt->city)) {
91
            $this->address[] = new Address(
92
                Address::OPTION_CITY,
93
                $opt->city
94
            );
95
        }
96
        if (!empty($opt->country)) {
97
            $this->address[] = new Address(
98
                Address::OPTION_COUNTRY,
99
                $opt->country
100
            );
101
        }
102
        if (!empty($opt->poBox)) {
103
            $this->address[] = new Address(
104
                Address::OPTION_PO_BOX,
105
                $opt->poBox
106
            );
107
        }
108
        if (!empty($opt->postalCode)) {
109
            $this->address[] = new Address(
110
                Address::OPTION_POSTAL_CODE,
111
                $opt->postalCode
112
            );
113
        }
114
        if (!empty($opt->state)) {
115
            $this->address[] = new Address(
116
                Address::OPTION_STATE,
117
                $opt->state
118
            );
119
        }
120
    }
121
}
122