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

AVAddress   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 95.65%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 17 13
A getCity() 0 4 1
A getStateProvince() 0 4 1
A getPostalCode() 0 7 2
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
}