1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use Ups\NodeInterface; |
8
|
|
|
use Ups\Entity\UnitOfMeasurement; |
9
|
|
|
|
10
|
|
|
class ShipmentTotalWeight implements NodeInterface |
11
|
|
|
{ |
12
|
|
|
private $unitOfMeasurement; |
13
|
|
|
private $Weight; |
14
|
|
|
|
15
|
|
View Code Duplication |
public function __construct($response = null) |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
if (null !== $response) { |
18
|
|
|
if (isset($response->unitOfMeasurement)) { |
19
|
|
|
$this->setUnitOfMeasurement($response->unitOfMeasurement); |
20
|
|
|
} |
21
|
|
|
if (isset($response->Weight)) { |
22
|
|
|
$this->setWeight($response->Weight); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param null|DOMDocument $document |
29
|
|
|
* |
30
|
|
|
* @return DOMElement |
31
|
|
|
*/ |
32
|
|
|
public function toNode(DOMDocument $document = null) |
33
|
|
|
{ |
34
|
|
|
if (null === $document) { |
35
|
|
|
$document = new DOMDocument(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$node = $document->createElement('ShipmentTotalWeight'); |
39
|
|
|
if ($this->getUnitOfMeasurement()) { |
40
|
|
|
$node->appendChild($this->getUnitOfMeasurement()->toNode($document)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$node->appendChild($document->createElement('Weight', $this->getWeight())); |
44
|
|
|
|
45
|
|
|
return $node; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return UnitOfMeasurement unitOfMeasurement |
50
|
|
|
*/ |
51
|
|
|
public function getUnitOfMeasurement() |
52
|
|
|
{ |
53
|
|
|
return $this->unitOfMeasurement; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param UnitOfMeasurement $unitOfMeasurement |
59
|
|
|
*/ |
60
|
|
|
public function setUnitOfMeasurement(UnitOfMeasurement $unitOfMeasurement) |
61
|
|
|
{ |
62
|
|
|
$this->unitOfMeasurement = $unitOfMeasurement; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return weight |
67
|
|
|
*/ |
68
|
|
|
public function getWeight() |
69
|
|
|
{ |
70
|
|
|
return $this->Weight; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param number $weight |
75
|
|
|
*/ |
76
|
|
|
public function setWeight($weight) |
77
|
|
|
{ |
78
|
|
|
if (!is_numeric($weight)) { |
79
|
|
|
throw new \Exception('Weight value should be a numeric value'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$this->Weight = $weight; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.