Completed
Pull Request — master (#80)
by
unknown
11:04 queued 05:59
created

getAddressClassification()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php namespace Ups\Entity;
2
3
4
use Ups\AddressValidation;
5
use Ups\Entity\AddressValidation\AVAddress;
6
use Ups\Entity\AddressValidation\AddressClassification;
7
8
class AddressValidationResponse
9
{
10
    protected $response;
11
    protected $requestAction;
12
13
    /**
14
     * AddressValidationResponse constructor.
15
     * @param \SimpleXMLElement $xmlDocument
16
     * @param $requestAction
17
     */
18 14
    public function __construct(\SimpleXMLElement $xmlDocument,$requestAction)
0 ignored issues
show
Coding Style introduced by
Expected 1 space between comma and argument "$requestAction"; 0 found
Loading history...
19
    {
20 14
        $this->response = $xmlDocument;
21 14
        $this->requestAction = $requestAction;
22 14
    }
23
24
    /**
25
     * Tells whether or not the NoCandidatesIndicator is present on the XML document.
26
     * This indicator is returned if the address is so badly formed that UPS is
27
     * unable to even offer any suggested alternatives
28
     *
29
     * @return bool
30
     */
31 5 View Code Duplication
    public function noCandidates()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32 2
    {
33 5
        if(AddressValidation::REQUEST_OPTION_ADDRESS_CLASSIFICATION == $this->requestAction) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
34 3
            throw new \BadMethodCallException(__METHOD__.' should not be called on Address Classification only requests.');
35 2
        }
36 2
        return isset($this->response->NoCandidatesIndicator);
37 2
    }
38
39
    /**
40
     * Tells whether or not the ValidAddressIndicator is present on the XML document.
41
     * This indicator is present if provided address is valid and represents a
42
     * single, unique address in the UPS Address Validation system.
43
     * @return bool
44
     */
45 3
    public function isValid()
46
    {
47 3
        if(AddressValidation::REQUEST_OPTION_ADDRESS_CLASSIFICATION == $this->requestAction) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
48 1
            return $this->response->AddressClassification->Code > 0;
49
        }
50 2
        return isset($this->response->ValidAddressIndicator);
51
    }
52
53
    /**
54
     * Tells whether or not the AmbiguousAddressIndicator is present on the XML document.
55
     * This indicator is present when the address provided is not specific enough to
56
     * be unique to one physical location, but provides enough
57
     *
58
     * @throws \BadMethodCallException
59
     * @return bool
60
     */
61 3 View Code Duplication
    public function isAmbiguous()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63 3
        if(AddressValidation::REQUEST_OPTION_ADDRESS_CLASSIFICATION == $this->requestAction) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
64 1
            throw new \BadMethodCallException(__METHOD__.' should not be called on Address Classification only requests.');
65
        }
66 2
        return isset($this->response->AmbiguousAddressIndicator);
67
    }
68
69
    /**
70
     * @throws \BadMethodCallException
71
     * @return AddressClassification
72
     */
73 2
    public function getAddressClassification()
74
    {
75 2
        if($this->requestAction < AddressValidation::REQUEST_OPTION_ADDRESS_CLASSIFICATION) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
76 1
            throw new \BadMethodCallException('Address Classification was not requested.');
77
        }
78 1
        return new AddressClassification($this->response->AddressClassification);
79
    }
80
81
    /**
82
     * @return \Ups\Entity\AddressValidation\Address[]
83
     */
84 1
    public function getCandidateAddressList()
85
    {
86 1
        if(!isset($this->response->AddressKeyFormat)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
87
            return [];
88
        }
89 1
        $candidates = [];
90 1
        foreach($this->response->AddressKeyFormat as $address) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FOREACH keyword; 0 found
Loading history...
91 1
            $candidates[] = new AVAddress($address);
92 1
        }
93 1
        return $candidates;
94
    }
95
96 1
    public function getValidatedAddress()
97
    {
98 1
        if($this->requestAction == AddressValidation::REQUEST_OPTION_ADDRESS_CLASSIFICATION) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
99
            throw new \BadMethodCallException('Only Address Classification was requested. There is no address.');
100
        }
101
102 1
        return new AVAddress($this->response->AddressKeyFormat);
103
    }
104
}