Completed
Pull Request — master (#80)
by
unknown
03:12
created

AVAddress   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 95.65%

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 17
c 4
b 2
f 1
lcom 1
cbo 1
dl 0
loc 112
ccs 22
cts 23
cp 0.9565
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 17 13
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 $region;
25
    /**
26
     * @var string
27
     */
28
    public $politicalDivision2;
29
    /**
30
     * @var string
31
     */
32
    public $politicalDivision1;
33
    /**
34
     * @var string
35
     */
36
    public $postcodePrimaryLow;
37
    /**
38
     * @var string
39
     */
40
    public $postcodeExtendedLow;
41
    /**
42
     * @var string
43
     */
44
    public $urbanization;
45
    /**
46
     * @var
47
     */
48
    public $countryCode;
49
50
    /**
51
     * Address constructor.
52
     * @param \SimpleXMLElement $xmlDoc
53
     */
54 2
    public function __construct(\SimpleXMLElement $xmlDoc)
55
    {
56 2
        if ($xmlDoc->count() == 0) {
57
            throw new \InvalidArgumentException(__METHOD__ . ': The passed object does not have any child nodes.');
58
        }
59 2
        $this->addressClassification = isset($xmlDoc->AddressClassification) ? new AddressClassification($xmlDoc->AddressClassification) : null;
60 2
        $this->consigneeName = isset($xmlDoc->ConsigneeName) ? (string)$xmlDoc->ConsigneeName : '';
61 2
        $this->buildingName = isset($xmlDoc->BuildingName) ? (string)$xmlDoc->BuildingName : '';
62 2
        $this->addressLine = isset($xmlDoc->AddressLine) ? (string)$xmlDoc->AddressLine : '';
63 2
        $this->region = isset($xmlDoc->Region) ? (string)$xmlDoc->Regions : '';
64 2
        $this->politicalDivision2 = isset($xmlDoc->PoliticalDivision2) ? (string)$xmlDoc->PoliticalDivision2 : '';
65 2
        $this->politicalDivision1 = isset($xmlDoc->PoliticalDivision1) ? (string)$xmlDoc->PoliticalDivision1 : '';
66 2
        $this->postcodePrimaryLow = isset($xmlDoc->PostcodePrimaryLow) ? (string)$xmlDoc->PostcodePrimaryLow : '';
67 2
        $this->postcodeExtendedLow = isset($xmlDoc->PostcodeExtendedLow) ? (string)$xmlDoc->PostcodeExtendedLow : '';
68 2
        $this->urbanization = isset($xmlDoc->Urbanization) ? (string)$xmlDoc->Urbanization : '';
69 2
        $this->consigneeName = isset($xmlDoc->CountryCode) ? (string)$xmlDoc->CountryCode : '';
70 2
    }
71
72
    /**
73
     * Convenience methods. Even though all properties are public, these methods provide a convenient interface to
74
     * retrieve commonly requested parts so that the user doesn't have to remember which API fields reference
75
     * which piece of information. For example, I won't have to remember that the city is in 'PoliticalDivision2'.
76
     */
77
78
    /**
79
     * @return string
80
     */
81 1
    public function getCity()
82
    {
83 1
        return $this->politicalDivision2;
84
    }
85
86
    /**
87
     * @return string
88
     */
89 1
    public function getStateProvince()
90
    {
91 1
        return $this->politicalDivision1;
92
    }
93
94
    /**
95
     * Return the address postal code
96
     *
97
     * @return string
98
     */
99 1
    public function getPostalCode()
100
    {
101 1
        return $this->postcodePrimaryLow;
102
    }
103
104
    /**
105
     * Return the address postal code with extension (i.e. the U.S. extended zip+4 postal code)
106
     *
107
     * @param string $divider
108
     * @return string
109
     */
110 1
    public function getPostalCodeWithExtension($divider = '-')
111
    {
112 1
        return $this->postcodePrimaryLow . $divider . $this->postcodeExtendedLow;
113
    }
114
}
115