|
1
|
|
|
<?php namespace SimpleUPS\Rates; |
|
2
|
|
|
|
|
3
|
|
|
use \SimpleUPS\Service; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* A shipping method is a shipping service associated with a price |
|
7
|
|
|
* @since 1.0 |
|
8
|
|
|
*/ |
|
9
|
|
|
class ShippingMethod extends \SimpleUPS\Model |
|
10
|
|
|
{ |
|
11
|
|
|
private |
|
12
|
|
|
/* @var \SimpleUPS\Service $service */ |
|
13
|
|
|
$service, |
|
14
|
|
|
/* @var integer|null $guaranteedDaysToDelivery */ |
|
15
|
|
|
$guaranteedDaysToDelivery, |
|
16
|
|
|
|
|
17
|
|
|
/* @var float $transportationCharges */ |
|
18
|
|
|
$transportationCharges, |
|
19
|
|
|
/* @var float $serviceOptionsCharges */ |
|
20
|
|
|
$serviceOptionsCharges, |
|
21
|
|
|
|
|
22
|
|
|
/* @var float $totalCharges */ |
|
23
|
|
|
$totalCharges, |
|
24
|
|
|
/* @var DateTime|null $scheduledDeliveryTime */ |
|
25
|
|
|
$scheduledDeliveryTime, |
|
26
|
|
|
|
|
27
|
|
|
/* @var string[]|null $warnings */ |
|
28
|
|
|
$warnings; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @internal |
|
32
|
|
|
* |
|
33
|
|
|
* @param integer $guaranteedDaysToDelivery |
|
34
|
|
|
* |
|
35
|
|
|
* @return ShippingMethod |
|
36
|
|
|
*/ |
|
37
|
|
|
public function setGuaranteedDaysToDelivery($guaranteedDaysToDelivery) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->guaranteedDaysToDelivery = $guaranteedDaysToDelivery; |
|
40
|
|
|
return $this; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return integer |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getGuaranteedDaysToDelivery() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->guaranteedDaysToDelivery; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @internal |
|
53
|
|
|
* |
|
54
|
|
|
* @param \DateTime $scheduledDeliveryTime |
|
55
|
|
|
* |
|
56
|
|
|
* @return ShippingMethod |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setScheduledDeliveryTime(\DateTime $scheduledDeliveryTime) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->scheduledDeliveryTime = $scheduledDeliveryTime; |
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return \DateTime |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getScheduledDeliveryTime() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->scheduledDeliveryTime; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @internal |
|
74
|
|
|
* |
|
75
|
|
|
* @param \SimpleUPS\Service $service |
|
76
|
|
|
* |
|
77
|
|
|
* @return ShippingMethod |
|
78
|
|
|
*/ |
|
79
|
|
|
public function setService(\SimpleUPS\Service $service) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->service = $service; |
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return \SimpleUPS\Service |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getService() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->service; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @internal |
|
95
|
|
|
* |
|
96
|
|
|
* @param float $serviceOptionsCharges |
|
97
|
|
|
* |
|
98
|
|
|
* @return ShippingMethod |
|
99
|
|
|
*/ |
|
100
|
|
|
public function setServiceOptionsCharges($serviceOptionsCharges) |
|
101
|
|
|
{ |
|
102
|
|
|
$this->serviceOptionsCharges = (float)$serviceOptionsCharges; |
|
103
|
|
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return float |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getServiceOptionsCharges() |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->serviceOptionsCharges; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @internal |
|
116
|
|
|
* |
|
117
|
|
|
* @param float $transportationCharges |
|
118
|
|
|
* |
|
119
|
|
|
* @return ShippingMethod |
|
120
|
|
|
*/ |
|
121
|
|
|
public function setTransportationCharges($transportationCharges) |
|
122
|
|
|
{ |
|
123
|
|
|
$this->transportationCharges = (float)$transportationCharges; |
|
124
|
|
|
return $this; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return float |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getTransportationCharges() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->transportationCharges; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @internal |
|
137
|
|
|
* |
|
138
|
|
|
* @param float $totalCharges |
|
139
|
|
|
* |
|
140
|
|
|
* @return ShippingMethod |
|
141
|
|
|
*/ |
|
142
|
|
|
public function setTotalCharges($totalCharges) |
|
143
|
|
|
{ |
|
144
|
|
|
$this->totalCharges = (float)$totalCharges; |
|
145
|
|
|
return $this; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return float |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getTotalCharges() |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->totalCharges; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @internal |
|
158
|
|
|
* |
|
159
|
|
|
* @param string $totalCharges |
|
|
|
|
|
|
160
|
|
|
* |
|
161
|
|
|
* @return ShippingMethod |
|
162
|
|
|
*/ |
|
163
|
|
|
public function addWarning($warning) |
|
164
|
|
|
{ |
|
165
|
|
|
if ($this->warnings === null) { |
|
166
|
|
|
$this->warnings = array(); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
$this->warnings[] = $warning; |
|
170
|
|
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Determine if UPS provided any warnings for this shipment |
|
175
|
|
|
* @see ShippingMethod::getWarnings() |
|
176
|
|
|
* @return bool |
|
177
|
|
|
*/ |
|
178
|
|
|
public function hasWarnings() |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->warnings == null; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Get warnings associated with this shipping method |
|
185
|
|
|
* @see ShippingMethod::hasWarnings() |
|
186
|
|
|
* @return string[] |
|
187
|
|
|
*/ |
|
188
|
|
|
public function getWarnings() |
|
189
|
|
|
{ |
|
190
|
|
|
return $this->warnings; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @internal |
|
195
|
|
|
* |
|
196
|
|
|
* @param \SimpleXMLElement $xml |
|
197
|
|
|
* |
|
198
|
|
|
* @return ShippingMethod |
|
199
|
|
|
*/ |
|
200
|
|
|
public static function fromXml(\SimpleXMLElement $xml) |
|
201
|
|
|
{ |
|
202
|
|
|
$shippingMethod = new ShippingMethod(); |
|
203
|
|
|
$shippingMethod->setIsResponse(); |
|
204
|
|
|
$shippingMethod->setService(Service::fromXml($xml->Service)); |
|
205
|
|
|
|
|
206
|
|
|
if (isset($xml->TotalCharges->MonetaryValue)) { |
|
207
|
|
|
$shippingMethod->setTotalCharges($xml->TotalCharges->MonetaryValue); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
if (isset($xml->TransportationCharges->MonetaryValue)) { |
|
211
|
|
|
$shippingMethod->setTransportationCharges($xml->TransportationCharges->MonetaryValue); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
if (isset($xml->ServiceOptionsCharges->MonetaryValue)) { |
|
215
|
|
|
$shippingMethod->setServiceOptionsCharges($xml->ServiceOptionsCharges->MonetaryValue); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
if (isset($xml->GuaranteedDaysToDelivery) && is_numeric($xml->GuaranteedDaysToDelivery)) { |
|
219
|
|
|
$shippingMethod->setGuaranteedDaysToDelivery($xml->GuaranteedDaysToDelivery); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
if (isset($xml->ScheduledDeliveryTime)) { |
|
223
|
|
|
$shippingMethod->setScheduledDeliveryTime(new \DateTime($xml->ScheduledDeliveryTime)); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
return $shippingMethod; |
|
227
|
|
|
} |
|
228
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.