1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Billogram\Model\Item; |
6
|
|
|
|
7
|
|
|
use Billogram\Model\CreatableFromArray; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Ibrahim Hizeoui <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
abstract class BaseItem implements CreatableFromArray |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var int |
16
|
|
|
*/ |
17
|
|
|
protected $itemNo; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $title; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $description; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $price; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var float |
36
|
|
|
*/ |
37
|
|
|
protected $vat; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $unit; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var Bookkeeping |
46
|
|
|
*/ |
47
|
|
|
protected $bookkeeping; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var \DateTime |
51
|
|
|
*/ |
52
|
|
|
protected $createdAt; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var \DateTime |
56
|
|
|
*/ |
57
|
|
|
protected $updatedAt; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return int |
61
|
|
|
*/ |
62
|
|
|
public function getItemNo(): int |
63
|
|
|
{ |
64
|
|
|
return $this->itemNo; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param int $itemNo |
69
|
|
|
* |
70
|
|
|
* @return Item |
71
|
|
|
*/ |
72
|
2 |
|
public function withItemNo(int $itemNo) |
73
|
|
|
{ |
74
|
2 |
|
$new = clone $this; |
75
|
2 |
|
$new->itemNo = $itemNo; |
76
|
|
|
|
77
|
2 |
|
return $new; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function getTitle(): string |
84
|
|
|
{ |
85
|
|
|
return $this->title; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param string $title |
90
|
|
|
* |
91
|
|
|
* @return Item |
92
|
|
|
*/ |
93
|
2 |
|
public function withTitle(string $title) |
94
|
|
|
{ |
95
|
2 |
|
$new = clone $this; |
96
|
2 |
|
$new->title = $title; |
97
|
|
|
|
98
|
2 |
|
return $new; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public function getDescription(): string |
105
|
|
|
{ |
106
|
|
|
return $this->description; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param string $description |
111
|
|
|
* |
112
|
|
|
* @return Item |
113
|
|
|
*/ |
114
|
2 |
|
public function withDescription(string $description) |
115
|
|
|
{ |
116
|
2 |
|
$new = clone $this; |
117
|
2 |
|
$new->description = $description; |
118
|
|
|
|
119
|
2 |
|
return $new; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getPrice(): string |
126
|
|
|
{ |
127
|
|
|
return $this->price; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param float $price |
132
|
|
|
* |
133
|
|
|
* @return Item |
134
|
|
|
*/ |
135
|
2 |
|
public function withPrice(float $price) |
136
|
|
|
{ |
137
|
2 |
|
$new = clone $this; |
138
|
2 |
|
$new->price = $price; |
|
|
|
|
139
|
|
|
|
140
|
2 |
|
return $new; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return float |
145
|
|
|
*/ |
146
|
|
|
public function getVat(): float |
147
|
|
|
{ |
148
|
|
|
return $this->vat; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param float $vat |
153
|
|
|
* |
154
|
|
|
* @return Item |
155
|
|
|
*/ |
156
|
2 |
|
public function withVat(float $vat) |
157
|
|
|
{ |
158
|
2 |
|
$new = clone $this; |
159
|
2 |
|
$new->vat = $vat; |
160
|
|
|
|
161
|
2 |
|
return $new; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return string |
166
|
|
|
*/ |
167
|
|
|
public function getUnit(): string |
168
|
|
|
{ |
169
|
|
|
return $this->unit; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param string $unit |
174
|
|
|
* |
175
|
|
|
* @return Item |
176
|
|
|
*/ |
177
|
2 |
|
public function withUnit(string $unit) |
178
|
|
|
{ |
179
|
2 |
|
$new = clone $this; |
180
|
2 |
|
$new->unit = $unit; |
181
|
|
|
|
182
|
2 |
|
return $new; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return Bookkeeping |
187
|
|
|
*/ |
188
|
|
|
public function getBookkeeping(): Bookkeeping |
189
|
|
|
{ |
190
|
|
|
return $this->bookkeeping; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param Bookkeeping $bookkeeping |
195
|
|
|
* |
196
|
|
|
* @return Item |
197
|
|
|
*/ |
198
|
5 |
|
public function withBookkeeping(Bookkeeping $bookkeeping) |
199
|
|
|
{ |
200
|
5 |
|
$new = clone $this; |
201
|
5 |
|
$new->bookkeeping = $bookkeeping; |
202
|
|
|
|
203
|
5 |
|
return $new; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return \DateTime |
208
|
|
|
*/ |
209
|
|
|
public function getCreatedAt(): \DateTime |
210
|
|
|
{ |
211
|
|
|
return $this->createdAt; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return \DateTime |
216
|
|
|
*/ |
217
|
|
|
public function getUpdatedAt(): \DateTime |
218
|
|
|
{ |
219
|
|
|
return $this->updatedAt; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @param \DateTime $createdAt |
224
|
|
|
*/ |
225
|
|
|
public function setCreatedAt(\DateTime $createdAt) |
226
|
|
|
{ |
227
|
|
|
$this->createdAt = $createdAt; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param \DateTime $updatedAt |
232
|
|
|
*/ |
233
|
|
|
public function setUpdatedAt(\DateTime $updatedAt) |
234
|
|
|
{ |
235
|
|
|
$this->updatedAt = $updatedAt; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Create an API response object from the HTTP response from the API server. |
240
|
|
|
* |
241
|
|
|
* @param array $data |
|
|
|
|
242
|
|
|
* |
243
|
|
|
* @return Item |
244
|
|
|
*/ |
245
|
4 |
|
public function toArray() |
246
|
|
|
{ |
247
|
4 |
|
$data = []; |
248
|
4 |
|
if ($this->title !== null) { |
249
|
2 |
|
$data['title'] = $this->title; |
250
|
|
|
} |
251
|
4 |
|
if ($this->itemNo !== null) { |
252
|
3 |
|
$data['item_no'] = $this->itemNo; |
253
|
|
|
} |
254
|
4 |
|
if ($this->description !== null) { |
255
|
2 |
|
$data['description'] = $this->description ?? null; |
256
|
|
|
} |
257
|
4 |
|
if ($this->price !== null) { |
258
|
2 |
|
$data['price'] = $this->price ?? null; |
259
|
|
|
} |
260
|
4 |
|
if ($this->vat !== null) { |
261
|
2 |
|
$data['vat'] = $this->vat ?? null; |
262
|
|
|
} |
263
|
4 |
|
if ($this->unit !== null) { |
264
|
2 |
|
$data['unit'] = $this->unit; |
265
|
|
|
} |
266
|
4 |
|
if ($this->bookkeeping !== null) { |
267
|
2 |
|
$data['bookkeeping'] = $this->bookkeeping->toArray(); |
268
|
|
|
} |
269
|
|
|
|
270
|
4 |
|
return $data; |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.