1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use Ups\NodeInterface; |
8
|
|
|
|
9
|
|
|
class Package implements NodeInterface |
10
|
|
|
{ |
11
|
|
|
const PKG_OVERSIZE1 = '1'; |
12
|
|
|
const PKG_OVERSIZE2 = '2'; |
13
|
|
|
const PKG_LARGE = '4'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var PackagingType |
17
|
|
|
*/ |
18
|
|
|
private $packagingType; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var PackageWeight |
22
|
|
|
*/ |
23
|
|
|
private $packageWeight; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $description; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var PackageServiceOptions |
32
|
|
|
*/ |
33
|
|
|
private $packageServiceOptions; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $upsPremiumCareIndicator; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var ReferenceNumber |
42
|
|
|
*/ |
43
|
|
|
private $referenceNumber; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var ReferenceNumber |
47
|
|
|
*/ |
48
|
|
|
private $referenceNumber2; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
private $trackingNumber; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var bool |
57
|
|
|
*/ |
58
|
|
|
private $isLargePackage; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var bool |
62
|
|
|
*/ |
63
|
|
|
private $additionalHandling; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var Dimensions|null |
67
|
|
|
*/ |
68
|
|
|
private $dimensions; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var Activity[] |
72
|
|
|
*/ |
73
|
|
|
private $activities = []; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param null|object $attributes |
77
|
|
|
*/ |
78
|
1 |
|
public function __construct($attributes = null) |
79
|
|
|
{ |
80
|
1 |
|
$this->setPackagingType(new PackagingType( |
81
|
1 |
|
isset($attributes->PackagingType) ? $attributes->PackagingType : null) |
82
|
1 |
|
); |
83
|
1 |
|
$this->setReferenceNumber(new ReferenceNumber()); |
84
|
1 |
|
$this->setReferenceNumber2(new ReferenceNumber()); |
85
|
1 |
|
$this->setPackageWeight(new PackageWeight()); |
86
|
1 |
|
$this->setPackageServiceOptions(new PackageServiceOptions()); |
87
|
|
|
|
88
|
1 |
|
if (null !== $attributes) { |
89
|
|
|
if (isset($attributes->PackageWeight)) { |
90
|
|
|
$this->setPackageWeight(new PackageWeight($attributes->PackageWeight)); |
91
|
|
|
} |
92
|
|
|
if (isset($attributes->Description)) { |
93
|
|
|
$this->setDescription($attributes->Description); |
94
|
|
|
} |
95
|
|
|
if (isset($attributes->PackageServiceOptions)) { |
96
|
|
|
$this->setPackageServiceOptions(new PackageServiceOptions($attributes->PackageServiceOptions)); |
97
|
|
|
} |
98
|
|
|
if (isset($attributes->UPSPremiumCareIndicator)) { |
99
|
|
|
$this->setUpsPremiumCareIndicator($attributes->UPSPremiumCareIndicator); |
100
|
|
|
} |
101
|
|
|
if (isset($attributes->ReferenceNumber)) { |
102
|
|
|
$this->setReferenceNumber(new ReferenceNumber($attributes->ReferenceNumber)); |
103
|
|
|
} |
104
|
|
|
if (isset($attributes->ReferenceNumber2)) { |
105
|
|
|
$this->setReferenceNumber2(new ReferenceNumber($attributes->ReferenceNumber2)); |
106
|
|
|
} |
107
|
|
|
if (isset($attributes->TrackingNumber)) { |
108
|
|
|
$this->setTrackingNumber($attributes->TrackingNumber); |
109
|
|
|
} |
110
|
|
|
if (isset($attributes->LargePackage)) { |
111
|
|
|
$this->setLargePackage($attributes->LargePackage); |
112
|
|
|
} |
113
|
|
|
if (isset($attributes->Dimensions)) { |
114
|
|
|
$this->setDimensions(new Dimensions($attributes->Dimensions)); |
115
|
|
|
} |
116
|
|
|
if (isset($attributes->Activity)) { |
117
|
|
|
$activities = $this->getActivities(); |
118
|
|
|
if (is_array($attributes->Activity)) { |
119
|
|
|
foreach ($attributes->Activity as $Activity) { |
120
|
|
|
$activities[] = new Activity($Activity); |
121
|
|
|
} |
122
|
|
|
} else { |
123
|
|
|
$activities[] = new Activity($attributes->Activity); |
124
|
|
|
} |
125
|
|
|
$this->setActivities($activities); |
126
|
|
|
} |
127
|
|
|
} |
128
|
1 |
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param null|DOMDocument $document |
132
|
|
|
* |
133
|
|
|
* @return DOMElement |
134
|
|
|
*/ |
135
|
1 |
|
public function toNode(DOMDocument $document = null) |
136
|
|
|
{ |
137
|
1 |
|
if (null === $document) { |
138
|
|
|
$document = new DOMDocument(); |
139
|
|
|
} |
140
|
|
|
|
141
|
1 |
|
$packageNode = $document->createElement('Package'); |
142
|
|
|
|
143
|
1 |
|
if ($this->getDescription()) { |
144
|
|
|
$packageNode->appendChild($document->createElement('Description', $this->getDescription())); |
145
|
|
|
} |
146
|
1 |
|
$packageNode->appendChild($this->getPackagingType()->toNode($document)); |
147
|
1 |
|
$packageNode->appendChild($this->getPackageWeight()->toNode($document)); |
148
|
|
|
|
149
|
|
|
|
150
|
1 |
|
if (null !== $this->getDimensions()) { |
151
|
|
|
$packageNode->appendChild($this->getDimensions()->toNode($document)); |
152
|
|
|
} |
153
|
|
|
|
154
|
1 |
|
if ($this->isLargePackage()) { |
155
|
|
|
$packageNode->appendChild($document->createElement('LargePackageIndicator')); |
156
|
|
|
} |
157
|
|
|
|
158
|
1 |
|
if ($this->getAdditionalHandling()) { |
159
|
|
|
$packageNode->appendChild($document->createElement('AdditionalHandling')); |
160
|
|
|
} |
161
|
|
|
|
162
|
1 |
|
if ($this->getPackageServiceOptions()) { |
163
|
1 |
|
$packageNode->appendChild($this->getPackageServiceOptions()->toNode($document)); |
164
|
1 |
|
} |
165
|
|
|
|
166
|
1 |
View Code Duplication |
if ($this->getReferenceNumber() |
|
|
|
|
167
|
1 |
|
&& !is_null($this->getReferenceNumber()->getCode()) |
168
|
1 |
|
&& !is_null($this->getReferenceNumber()->getValue()) |
169
|
1 |
|
) { |
170
|
|
|
$packageNode->appendChild($this->getReferenceNumber()->toNode($document)); |
171
|
|
|
} |
172
|
|
|
|
173
|
1 |
View Code Duplication |
if ($this->getReferenceNumber2() |
|
|
|
|
174
|
1 |
|
&& !is_null($this->getReferenceNumber2()->getCode()) |
175
|
1 |
|
&& !is_null($this->getReferenceNumber2()->getValue()) |
176
|
1 |
|
) { |
177
|
|
|
$packageNode->appendChild($this->getReferenceNumber2()->toNode($document)); |
178
|
|
|
} |
179
|
|
|
|
180
|
1 |
|
return $packageNode; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return Activity[] |
185
|
|
|
*/ |
186
|
|
|
public function getActivities() |
187
|
|
|
{ |
188
|
|
|
return $this->activities; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param Activity[] $activities |
193
|
|
|
* |
194
|
|
|
* @return Package |
195
|
|
|
*/ |
196
|
|
|
public function setActivities(array $activities) |
197
|
|
|
{ |
198
|
|
|
$this->activities = $activities; |
199
|
|
|
|
200
|
|
|
return $this; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return string |
205
|
|
|
*/ |
206
|
1 |
|
public function getDescription() |
207
|
|
|
{ |
208
|
1 |
|
return $this->description; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @param string $description |
213
|
|
|
* |
214
|
|
|
* @return Package |
215
|
|
|
*/ |
216
|
|
|
public function setDescription($description) |
217
|
|
|
{ |
218
|
|
|
$this->description = $description; |
219
|
|
|
|
220
|
|
|
return $this; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @return Dimensions|null |
225
|
|
|
*/ |
226
|
1 |
|
public function getDimensions() |
227
|
|
|
{ |
228
|
1 |
|
return $this->dimensions; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @param Dimensions $dimensions |
233
|
|
|
* |
234
|
|
|
* @return Package |
235
|
|
|
*/ |
236
|
|
|
public function setDimensions(Dimensions $dimensions) |
237
|
|
|
{ |
238
|
|
|
$this->dimensions = $dimensions; |
239
|
|
|
|
240
|
|
|
return $this; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @return bool |
245
|
|
|
*/ |
246
|
1 |
|
public function isLargePackage() |
247
|
|
|
{ |
248
|
1 |
|
return $this->isLargePackage; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param bool $largePackage |
253
|
|
|
* |
254
|
|
|
* @return Package |
255
|
|
|
*/ |
256
|
|
|
public function setLargePackage($largePackage) |
257
|
|
|
{ |
258
|
|
|
$this->isLargePackage = $largePackage; |
259
|
|
|
|
260
|
|
|
return $this; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return PackageServiceOptions |
265
|
|
|
*/ |
266
|
1 |
|
public function getPackageServiceOptions() |
267
|
|
|
{ |
268
|
1 |
|
return $this->packageServiceOptions; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @param PackageServiceOptions $packageServiceOptions |
273
|
|
|
* |
274
|
|
|
* @return Package |
275
|
|
|
*/ |
276
|
1 |
|
public function setPackageServiceOptions(PackageServiceOptions $packageServiceOptions) |
277
|
|
|
{ |
278
|
1 |
|
$this->packageServiceOptions = $packageServiceOptions; |
279
|
|
|
|
280
|
1 |
|
return $this; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @return PackageWeight |
285
|
|
|
*/ |
286
|
1 |
|
public function getPackageWeight() |
287
|
|
|
{ |
288
|
1 |
|
return $this->packageWeight; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @param PackageWeight $packageWeight |
293
|
|
|
* |
294
|
|
|
* @return Package |
295
|
|
|
*/ |
296
|
1 |
|
public function setPackageWeight(PackageWeight $packageWeight) |
297
|
|
|
{ |
298
|
1 |
|
$this->packageWeight = $packageWeight; |
299
|
|
|
|
300
|
1 |
|
return $this; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @return PackagingType |
305
|
|
|
*/ |
306
|
1 |
|
public function getPackagingType() |
307
|
|
|
{ |
308
|
1 |
|
return $this->packagingType; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @param PackagingType $packagingType |
313
|
|
|
* |
314
|
|
|
* @return Package |
315
|
|
|
*/ |
316
|
1 |
|
public function setPackagingType(PackagingType $packagingType) |
317
|
|
|
{ |
318
|
1 |
|
$this->packagingType = $packagingType; |
319
|
|
|
|
320
|
1 |
|
return $this; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @return ReferenceNumber |
325
|
|
|
*/ |
326
|
1 |
|
public function getReferenceNumber() |
327
|
|
|
{ |
328
|
1 |
|
return $this->referenceNumber; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @param ReferenceNumber $referenceNumber |
333
|
|
|
* |
334
|
|
|
* @return Package |
335
|
|
|
*/ |
336
|
1 |
|
public function setReferenceNumber(ReferenceNumber $referenceNumber) |
337
|
|
|
{ |
338
|
1 |
|
$this->referenceNumber = $referenceNumber; |
339
|
|
|
|
340
|
1 |
|
return $this; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
public function removeReferenceNumber() |
344
|
|
|
{ |
345
|
|
|
$this->referenceNumber = null; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* @return ReferenceNumber |
350
|
|
|
*/ |
351
|
1 |
|
public function getReferenceNumber2() |
352
|
|
|
{ |
353
|
1 |
|
return $this->referenceNumber2; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @param ReferenceNumber $referenceNumber |
358
|
|
|
* |
359
|
|
|
* @return Package |
360
|
|
|
*/ |
361
|
1 |
|
public function setReferenceNumber2(ReferenceNumber $referenceNumber) |
362
|
|
|
{ |
363
|
1 |
|
$this->referenceNumber2 = $referenceNumber; |
364
|
|
|
|
365
|
1 |
|
return $this; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
public function removeReferenceNumber2() |
369
|
|
|
{ |
370
|
|
|
$this->referenceNumber2 = null; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* @return string |
375
|
|
|
*/ |
376
|
|
|
public function getTrackingNumber() |
377
|
|
|
{ |
378
|
|
|
return $this->trackingNumber; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* @param string $trackingNumber |
383
|
|
|
* |
384
|
|
|
* @return Package |
385
|
|
|
*/ |
386
|
|
|
public function setTrackingNumber($trackingNumber) |
387
|
|
|
{ |
388
|
|
|
$this->trackingNumber = $trackingNumber; |
389
|
|
|
|
390
|
|
|
return $this; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* @return string |
395
|
|
|
*/ |
396
|
|
|
public function getUpsPremiumCareIndicator() |
397
|
|
|
{ |
398
|
|
|
return $this->upsPremiumCareIndicator; |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* @param string $upsPremiumCareIndicator |
403
|
|
|
* |
404
|
|
|
* @return Package |
405
|
|
|
*/ |
406
|
|
|
public function setUpsPremiumCareIndicator($upsPremiumCareIndicator) |
407
|
|
|
{ |
408
|
|
|
$this->upsPremiumCareIndicator = $upsPremiumCareIndicator; |
409
|
|
|
|
410
|
|
|
return $this; |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* @return boolean |
415
|
|
|
*/ |
416
|
1 |
|
public function getAdditionalHandling() |
417
|
|
|
{ |
418
|
1 |
|
return $this->additionalHandling; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* @param boolean $additionalHandling |
423
|
|
|
*/ |
424
|
|
|
public function setAdditionalHandling($additionalHandling) |
425
|
|
|
{ |
426
|
|
|
$this->additionalHandling = $additionalHandling; |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
|
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.