Completed
Push — master ( 0d5428...cb556d )
by Stefan
03:25
created

AVAddress::getBuildingName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace Ups\Entity\AddressValidation;
2
3
class AVAddress
4
{
5
    /**
6
     * @var null|AddressClassification
7
     */
8
    public $addressClassification;
9
    /**
10
     * @var string
11
     */
12
    public $consigneeName;
13
    /**
14
     * @var string
15
     */
16
    public $buildingName;
17
    /**
18
     * @var string
19
     */
20
    public $addressLine;
21
    /**
22
     * @var string
23
     */
24
    public $addressLine2;
25
    /**
26
     * @var string
27
     */
28
    public $addressLine3;
29
    /**
30
     * @var string
31
     */
32
    public $region;
33
    /**
34
     * @var string
35
     */
36
    public $politicalDivision2;
37
    /**
38
     * @var string
39
     */
40
    public $politicalDivision1;
41
    /**
42
     * @var string
43
     */
44
    public $postcodePrimaryLow;
45
    /**
46
     * @var string
47
     */
48
    public $postcodeExtendedLow;
49
    /**
50
     * @var string
51
     */
52
    public $urbanization;
53
    /**
54
     * @var
55
     */
56
    public $countryCode;
57
58
    /**
59
     * Address constructor.
60
     * @param \SimpleXMLElement $xmlDoc
61
     */
62 2
    public function __construct(\SimpleXMLElement $xmlDoc)
63
    {
64 2
        if ($xmlDoc->count() == 0) {
65
            throw new \InvalidArgumentException(__METHOD__ . ': The passed object does not have any child nodes.');
66
        }
67 2
        $this->addressClassification = isset($xmlDoc->AddressClassification) ? new AddressClassification($xmlDoc->AddressClassification) : null;
68 2
        $this->consigneeName = isset($xmlDoc->ConsigneeName) ? (string)$xmlDoc->ConsigneeName : '';
69 2
        $this->buildingName = isset($xmlDoc->BuildingName) ? (string)$xmlDoc->BuildingName : '';
70 2
        if (isset($xmlDoc->AddressLine)) {
71 2
            for ($i = 0, $len = count($xmlDoc->AddressLine); $i < $len; $i++) {
72 2
                $var = 'addressLine' . ($i > 0 ? $i + 1 : '');
73 2
                $this->{$var} = isset($xmlDoc->AddressLine[$i]) ? (string) $xmlDoc->AddressLine[$i] : '';
74 2
            }
75 2
        }
76 2
        $this->region = isset($xmlDoc->Region) ? (string)$xmlDoc->Region : '';
77 2
        $this->politicalDivision2 = isset($xmlDoc->PoliticalDivision2) ? (string)$xmlDoc->PoliticalDivision2 : '';
78 2
        $this->politicalDivision1 = isset($xmlDoc->PoliticalDivision1) ? (string)$xmlDoc->PoliticalDivision1 : '';
79 2
        $this->postcodePrimaryLow = isset($xmlDoc->PostcodePrimaryLow) ? (string)$xmlDoc->PostcodePrimaryLow : '';
80 2
        $this->postcodeExtendedLow = isset($xmlDoc->PostcodeExtendedLow) ? (string)$xmlDoc->PostcodeExtendedLow : '';
81 2
        $this->urbanization = isset($xmlDoc->Urbanization) ? (string)$xmlDoc->Urbanization : '';
82 2
        $this->countryCode = isset($xmlDoc->CountryCode) ? (string)$xmlDoc->CountryCode : '';
83 2
    }
84
85
    /**
86
     * Convenience methods. Even though all properties are public, these methods provide a convenient interface to
87
     * retrieve commonly requested parts so that the user doesn't have to remember which API fields reference
88
     * which piece of information. For example, I won't have to remember that the city is in 'PoliticalDivision2'.
89
     */
90
91
    /**
92
     * @return string
93
     */
94 1
    public function getCity()
95
    {
96 1
        return $this->politicalDivision2;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getRegion()
103
    {
104
        return $this->region;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function getConsigneeName()
111
    {
112
        return $this->consigneeName;
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function getUrbanization()
119
    {
120
        return $this->urbanization;
121
    }
122
123
    /**
124
     * @return string
125
     */
126
    public function getBuildingName()
127
    {
128
        return $this->buildingName;
129
    }
130
131
    /**
132
     * @return string
133
     */
134 1
    public function getStateProvince()
135
    {
136 1
        return $this->politicalDivision1;
137
    }
138
139
    /**
140
     * Return the address postal code
141
     *
142
     * @return string
143
     */
144 1
    public function getPostalCode()
145
    {
146 1
        return $this->postcodePrimaryLow;
147
    }
148
149
    /**
150
     * Return the address postal code with extension (i.e. the U.S. extended zip+4 postal code)
151
     *
152
     * @param string $divider
153
     * @return string
154
     */
155 1
    public function getPostalCodeWithExtension($divider = '-')
156
    {
157 1
        return $this->postcodePrimaryLow . $divider . $this->postcodeExtendedLow;
158
    }
159
160
    /**
161
     * @return string
162
     *
163
     * @param int $lineNumber
164
     * @return string
165
     */
166
    public function getAddressLine($lineNumber = 1)
167
    {
168
        $var = 'addressLine' . ($lineNumber > 1 ? $lineNumber : '');
169
        return $this->{$var};
170
    }
171
}
172