1 | <?php |
||
5 | class Item |
||
6 | { |
||
7 | /** |
||
8 | * Item Stock Keeping Unit |
||
9 | * |
||
10 | * @var string $sku |
||
11 | */ |
||
12 | protected $sku; |
||
13 | |||
14 | /** |
||
15 | * Item name |
||
16 | * |
||
17 | * @var string $name |
||
18 | */ |
||
19 | protected $name; |
||
20 | |||
21 | /** |
||
22 | * Item price |
||
23 | * |
||
24 | * @var string $price |
||
25 | */ |
||
26 | protected $price; |
||
27 | |||
28 | /** |
||
29 | * Item tax |
||
30 | * |
||
31 | * @var string $price |
||
32 | */ |
||
33 | protected $tax; |
||
34 | |||
35 | /** |
||
36 | * @param string $sku Item Stock Keeping Unit |
||
37 | * @param string $name Item name |
||
38 | * @param string $price Item price with two digits after decimal point, e.g. '123.00' |
||
39 | * @param string $tax Optional tax with two digits after decimal point, e.g. '23.00' |
||
40 | * |
||
41 | * @throws \Exception When the price format is invalid |
||
42 | */ |
||
43 | public function __construct($sku, $name, $price, $tax = '0.00') |
||
50 | |||
51 | // Setters |
||
52 | |||
53 | /** |
||
54 | * @param string $name |
||
55 | */ |
||
56 | public function setName($name) |
||
60 | |||
61 | /** |
||
62 | * @param string $sku |
||
63 | */ |
||
64 | public function setSku($sku) |
||
68 | |||
69 | /** |
||
70 | * @param string $price Item price with two digits after decimal point, e.g. '123.00' |
||
71 | * |
||
72 | * @throws \Exception When the price format is invalid |
||
73 | */ |
||
74 | public function setPrice($price) |
||
79 | |||
80 | /** |
||
81 | * @param string $tax Optional tax with two digits after decimal point, e.g. '23.00' |
||
82 | * |
||
83 | * @throws \Exception When the tax format is invalid |
||
84 | */ |
||
85 | public function setTax($tax) |
||
90 | |||
91 | // Getters |
||
92 | |||
93 | /** |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getSku() |
||
100 | |||
101 | /** |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getName() |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | public function getPrice() |
||
116 | |||
117 | /** |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getTax() |
||
124 | |||
125 | /** |
||
126 | * Validate amount format |
||
127 | * |
||
128 | * Checks if amount is a number with two digits after decimal point |
||
129 | * |
||
130 | * @param mixed $amount |
||
131 | * |
||
132 | * @throws \Exception When the amount format is invalid |
||
133 | */ |
||
134 | protected function validateAmountFormat($amount) |
||
140 | } |
||
141 |