1
|
|
|
<?php namespace SimpleUPS\RegionValidate; |
2
|
|
|
|
3
|
|
|
use SimpleUPS\Address; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* A suggested region is provided during region validation when UPS provides more |
7
|
|
|
* information about a region. Usually this means something was wrong with the |
8
|
|
|
* original region being validated. |
9
|
|
|
* If a postal code was omitted in validation, the postal code low and high ends will |
10
|
|
|
* be populated with the postal codes that fit within that region. |
11
|
|
|
* @see \SimpleUPS\UPS::isValidRegion() |
12
|
|
|
* @see \SimpleUPS\UPS::getRegionSuggestions() |
13
|
|
|
* @since 1.0 |
14
|
|
|
*/ |
15
|
|
|
class RegionSuggestion |
16
|
|
|
{ |
17
|
|
|
private |
18
|
|
|
$rank, |
19
|
|
|
$quality, |
20
|
|
|
$address, |
21
|
|
|
$postalCodeLowEnd, |
22
|
|
|
$postalCodeHighEnd; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @internal |
26
|
|
|
* |
27
|
|
|
* @param integer $rank |
28
|
|
|
* |
29
|
|
|
* @return RegionSuggestion |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
public function setRank($rank) |
33
|
|
|
{ |
34
|
|
|
$this->rank = $rank; |
35
|
|
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The rank of each region suggestion |
40
|
|
|
* @since 1.0 |
41
|
|
|
* @return integer |
42
|
|
|
*/ |
43
|
|
|
public function getRank() |
44
|
|
|
{ |
45
|
|
|
return $this->rank; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @internal |
50
|
|
|
* |
51
|
|
|
* @param float $quality |
52
|
|
|
* |
53
|
|
|
* @return RegionSuggestion |
54
|
|
|
*/ |
55
|
|
|
public function setQuality($quality) |
56
|
|
|
{ |
57
|
|
|
$this->quality = $quality; |
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The quality factor, which describes the accuracy of the result compared to the request. |
63
|
|
|
* <ul> |
64
|
|
|
* <li>1.0 = Exact match. Usually this means UPS provided a correction</li> |
65
|
|
|
* <li>95-.99 = Very close match.</li> |
66
|
|
|
* <li>90-.94 = Close match.</li> |
67
|
|
|
* <li>70-.89 = Possible match.</li> |
68
|
|
|
* <li>00-.69 = Poor match</li> |
69
|
|
|
* </ul> |
70
|
|
|
* @see isCorrected() |
71
|
|
|
* @since 1.0 |
72
|
|
|
* @return float |
73
|
|
|
*/ |
74
|
|
|
public function getQuality() |
75
|
|
|
{ |
76
|
|
|
return $this->quality; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Determine if this region is a correction of the original region requested for validation |
81
|
|
|
* @see getQuality() |
82
|
|
|
* @since 1.0 |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function isCorrected() |
86
|
|
|
{ |
87
|
|
|
return $this->getQuality() == 1; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @internal |
92
|
|
|
* |
93
|
|
|
* @param \SimpleUPS\Address $address |
94
|
|
|
* |
95
|
|
|
* @return RegionSuggestion |
96
|
|
|
*/ |
97
|
|
|
public function setAddress(Address $address) |
98
|
|
|
{ |
99
|
|
|
$this->address = $address; |
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Provides the city, state/province, and country code |
105
|
|
|
* @since 1.0 |
106
|
|
|
* @return \SimpleUPS\Address |
107
|
|
|
*/ |
108
|
|
|
public function getAddress() |
109
|
|
|
{ |
110
|
|
|
return $this->address; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @internal |
115
|
|
|
* |
116
|
|
|
* @param integer $postalCodeLowEnd |
117
|
|
|
* |
118
|
|
|
* @return RegionSuggestion |
119
|
|
|
*/ |
120
|
|
|
public function setPostalCodeLowEnd($postalCodeLowEnd) |
121
|
|
|
{ |
122
|
|
|
$this->postalCodeLowEnd = $postalCodeLowEnd; |
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* When matches for a given region combination, a postal code range may be associated with each match. This is the low end of the range. |
128
|
|
|
* @since 1.0 |
129
|
|
|
* @return integer |
130
|
|
|
*/ |
131
|
|
|
public function getPostalCodeLowEnd() |
132
|
|
|
{ |
133
|
|
|
return $this->postalCodeLowEnd; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @internal |
138
|
|
|
* |
139
|
|
|
* @param integer $postalCodeHighEnd |
140
|
|
|
* |
141
|
|
|
* @return RegionSuggestion |
142
|
|
|
*/ |
143
|
|
|
public function setPostalCodeHighEnd($postalCodeHighEnd) |
144
|
|
|
{ |
145
|
|
|
$this->postalCodeHighEnd = $postalCodeHighEnd; |
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* When matches for a given region combination, a postal code range may be associated with each match. This is the high end of the range. |
151
|
|
|
* @since 1.0 |
152
|
|
|
* @return integer |
153
|
|
|
*/ |
154
|
|
|
public function getPostalCodeHighEnd() |
155
|
|
|
{ |
156
|
|
|
return $this->postalCodeHighEnd; |
157
|
|
|
} |
158
|
|
|
} |