Completed
Pull Request — master (#90)
by
unknown
03:10
created

AVAddress   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 84.85%

Importance

Changes 7
Bugs 2 Features 1
Metric Value
wmc 24
c 7
b 2
f 1
lcom 1
cbo 1
dl 0
loc 130
ccs 28
cts 33
cp 0.8485
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
F __construct() 0 27 20
A getCity() 0 4 1
A getStateProvince() 0 4 1
A getPostalCode() 0 4 1
A getPostalCodeWithExtension() 0 4 1
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
                if ($i === 0) {
73 2
                    $this->addressLine = isset($xmlDoc->AddressLine[$i]) ? (string) $xmlDoc->AddressLine[$i] : '';
74 2
                } elseif ($i === 1) {
75
                    $this->addressLine2 = isset($xmlDoc->AddressLine[$i]) ? (string) $xmlDoc->AddressLine[$i] : '';
76
                } elseif ($i === 2) {
77
                    $this->addressLine3 = isset($xmlDoc->AddressLine[$i]) ? (string) $xmlDoc->AddressLine[$i] : '';
78
                }
79 2
            }
80 2
        }
81 2
        $this->region = isset($xmlDoc->Region) ? (string)$xmlDoc->Region : '';
82 2
        $this->politicalDivision2 = isset($xmlDoc->PoliticalDivision2) ? (string)$xmlDoc->PoliticalDivision2 : '';
83 2
        $this->politicalDivision1 = isset($xmlDoc->PoliticalDivision1) ? (string)$xmlDoc->PoliticalDivision1 : '';
84 2
        $this->postcodePrimaryLow = isset($xmlDoc->PostcodePrimaryLow) ? (string)$xmlDoc->PostcodePrimaryLow : '';
85 2
        $this->postcodeExtendedLow = isset($xmlDoc->PostcodeExtendedLow) ? (string)$xmlDoc->PostcodeExtendedLow : '';
86 2
        $this->urbanization = isset($xmlDoc->Urbanization) ? (string)$xmlDoc->Urbanization : '';
87 2
        $this->countryCode = isset($xmlDoc->CountryCode) ? (string)$xmlDoc->CountryCode : '';
88 2
    }
89
90
    /**
91
     * Convenience methods. Even though all properties are public, these methods provide a convenient interface to
92
     * retrieve commonly requested parts so that the user doesn't have to remember which API fields reference
93
     * which piece of information. For example, I won't have to remember that the city is in 'PoliticalDivision2'.
94
     */
95
96
    /**
97
     * @return string
98
     */
99 1
    public function getCity()
100
    {
101 1
        return $this->politicalDivision2;
102
    }
103
104
    /**
105
     * @return string
106
     */
107 1
    public function getStateProvince()
108
    {
109 1
        return $this->politicalDivision1;
110
    }
111
112
    /**
113
     * Return the address postal code
114
     *
115
     * @return string
116
     */
117 1
    public function getPostalCode()
118
    {
119 1
        return $this->postcodePrimaryLow;
120
    }
121
122
    /**
123
     * Return the address postal code with extension (i.e. the U.S. extended zip+4 postal code)
124
     *
125
     * @param string $divider
126
     * @return string
127
     */
128 1
    public function getPostalCodeWithExtension($divider = '-')
129
    {
130 1
        return $this->postcodePrimaryLow . $divider . $this->postcodeExtendedLow;
131
    }
132
}
133