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

AVAddress::getStateProvince()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Ups\Entity\AddressValidation;
2
3
class AVAddress
4
{
5
    public $addressClassification;
6
    public $consigneeName;
7
    public $buildingName;
8
    public $addressLine;
9
    public $region;
10
    public $politicalDivision2;
11
    public $politicalDivision1;
12
    public $postcodePrimaryLow;
13
    public $postcodeExtendedLow;
14
    public $urbanization;
15
    public $countryCode;
16
17
    /**
18
     * Address constructor.
19
     * @param \SimpleXMLElement $xmlDoc
20
     */
21 2
    public function __construct(\SimpleXMLElement $xmlDoc)
22
    {
23 2
        if ($xmlDoc->count() == 0) {
24
            throw new \InvalidArgumentException(__METHOD__ . ': The passed object does not have any child nodes.');
25
        }
26 2
        $this->addressClassification = isset($xmlDoc->AddressClassification) ? new AddressClassification($xmlDoc->AddressClassification) : null;
27 2
        $this->consigneeName = isset($xmlDoc->ConsigneeName) ? (string)$xmlDoc->ConsigneeName : '';
28 2
        $this->buildingName = isset($xmlDoc->BuildingName) ? (string)$xmlDoc->BuildingName : '';
29 2
        $this->addressLine = isset($xmlDoc->AddressLine) ? (string)$xmlDoc->AddressLine : '';
30 2
        $this->region = isset($xmlDoc->Region) ? (string)$xmlDoc->Regions : '';
31 2
        $this->politicalDivision2 = isset($xmlDoc->PoliticalDivision2) ? (string)$xmlDoc->PoliticalDivision2 : '';
32 2
        $this->politicalDivision1 = isset($xmlDoc->PoliticalDivision1) ? (string)$xmlDoc->PoliticalDivision1 : '';
33 2
        $this->postcodePrimaryLow = isset($xmlDoc->PostcodePrimaryLow) ? (string)$xmlDoc->PostcodePrimaryLow : '';
34 2
        $this->postcodeExtendedLow = isset($xmlDoc->PostcodeExtendedLow) ? (string)$xmlDoc->PostcodeExtendedLow : '';
35 2
        $this->urbanization = isset($xmlDoc->Urbanization) ? (string)$xmlDoc->Urbanization : '';
36 2
        $this->consigneeName = isset($xmlDoc->CountryCode) ? (string)$xmlDoc->CountryCode : '';
37 2
    }
38
39
    /**
40
     * Convenience methods. Even though all properties are public, these methods provide a convenient interface to
41
     * retrieve commonly requested parts so that the user doesn't have to remember which API fields reference
42
     * which piece of information. For example, I won't have to remember that the city is in 'PoliticalDivision2'.
43
     */
44
45
    /**
46
     * @return string
47
     */
48 1
    public function getCity()
49
    {
50 1
        return $this->politicalDivision2;
51
    }
52
53
    /**
54
     * @return string
55
     */
56 1
    public function getStateProvince()
57
    {
58 1
        return $this->politicalDivision1;
59
    }
60
61
    /**
62
     * @param bool $withExtended
63
     * @param string $extendedDivider
64
     * @return string
65
     */
66 1
    public function getPostalCode($withExtended = false, $extendedDivider = '-')
67
    {
68 1
        if ($withExtended) {
69 1
            return $this->postcodePrimaryLow . $extendedDivider . $this->postcodeExtendedLow;
70
        }
71 1
        return $this->postcodePrimaryLow;
72
    }
73
}
74