1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MelhorEnvio\Resources\Shipment; |
4
|
|
|
|
5
|
|
|
use MelhorEnvio\Validations\Number; |
6
|
|
|
use InvalidArgumentException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Product |
10
|
|
|
* @package MelhorEnvio\Resources\Shipment |
11
|
|
|
*/ |
12
|
|
|
class Product extends Volume |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $id; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var int|float |
21
|
|
|
*/ |
22
|
|
|
protected $insuranceValue; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var int |
26
|
|
|
*/ |
27
|
|
|
protected $quantity; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Product constructor. |
31
|
|
|
* |
32
|
|
|
* @param string $id |
33
|
|
|
* @param $height |
34
|
|
|
* @param $width |
35
|
|
|
* @param $length |
36
|
|
|
* @param $weight |
37
|
|
|
* @param $insuranceValue |
38
|
|
|
* @param $quantity |
39
|
|
|
*/ |
40
|
|
|
public function __construct($id, $height, $width, $length, $weight, $insuranceValue, $quantity = 1) |
41
|
|
|
{ |
42
|
|
|
$this->setId($id); |
43
|
|
|
$this->setHeight($height); |
44
|
|
|
$this->setWidth($width); |
45
|
|
|
$this->setLength($length); |
46
|
|
|
$this->setWeight($weight); |
47
|
|
|
$this->setInsuranceValue($insuranceValue); |
48
|
|
|
$this->setQuantity($quantity); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getId() |
55
|
|
|
{ |
56
|
|
|
return $this->id; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $id |
61
|
|
|
*/ |
62
|
|
|
public function setId($id) |
63
|
|
|
{ |
64
|
|
|
$this->id = (string) $id; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return int |
69
|
|
|
*/ |
70
|
|
|
public function getQuantity() |
71
|
|
|
{ |
72
|
|
|
return $this->quantity; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param int $quantity |
77
|
|
|
*/ |
78
|
|
|
public function setQuantity($quantity) |
79
|
|
|
{ |
80
|
|
|
if (! Number::isPositiveInteger($quantity)) { |
81
|
|
|
throw new InvalidArgumentException("quantity"); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$this->quantity = $quantity; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return int|float |
89
|
|
|
*/ |
90
|
|
|
public function getInsuranceValue() |
91
|
|
|
{ |
92
|
|
|
return $this->insuranceValue; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param int|float $insuranceValue |
97
|
|
|
*/ |
98
|
|
|
public function setInsuranceValue($insuranceValue) |
99
|
|
|
{ |
100
|
|
|
$this->validateNumericArgument($insuranceValue, 'insurance_value'); |
101
|
|
|
|
102
|
|
|
$this->insuranceValue = $insuranceValue; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function toArray() |
109
|
|
|
{ |
110
|
|
|
return [ |
111
|
|
|
'id' => $this->getId(), |
112
|
|
|
'height' => $this->getHeight(), |
113
|
|
|
'width' => $this->getWidth(), |
114
|
|
|
'length' => $this->getLength(), |
115
|
|
|
'weight' => $this->getWeight(), |
116
|
|
|
'insurance_value' => $this->getInsuranceValue(), |
117
|
|
|
'quantity' => $this->getQuantity(), |
118
|
|
|
]; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|