1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainFoundation\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Loevgaard\DandomainFoundation; |
7
|
|
|
use Loevgaard\DandomainFoundation\Entity\Generated\OrderLineInterface; |
8
|
|
|
use Loevgaard\DandomainFoundation\Entity\Generated\OrderLineTrait; |
9
|
|
|
use Money\Money; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @ORM\Entity() |
13
|
|
|
* @ORM\Table(name="loevgaard_dandomain_order_lines") |
14
|
|
|
*/ |
15
|
|
|
class OrderLine implements OrderLineInterface |
16
|
|
|
{ |
17
|
|
|
use OrderLineTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var int |
21
|
|
|
* |
22
|
|
|
* @ORM\Id |
23
|
|
|
* @ORM\GeneratedValue |
24
|
|
|
* @ORM\Column(type="integer") |
25
|
|
|
**/ |
26
|
|
|
protected $id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
* |
31
|
|
|
* @ORM\Column(type="integer", unique=true) |
32
|
|
|
*/ |
33
|
|
|
protected $externalId; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string|null |
37
|
|
|
* |
38
|
|
|
* @ORM\Column(nullable=true, type="string", length=191) |
39
|
|
|
*/ |
40
|
|
|
protected $fileUrl; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var int|null |
44
|
|
|
* |
45
|
|
|
* @ORM\Column(nullable=true, type="string", length=191) |
46
|
|
|
*/ |
47
|
|
|
protected $productNumber; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string|null |
51
|
|
|
* |
52
|
|
|
* @ORM\Column(nullable=true, type="string", length=191) |
53
|
|
|
*/ |
54
|
|
|
protected $productName; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var int|null |
58
|
|
|
* |
59
|
|
|
* @ORM\Column(nullable=true, type="integer") |
60
|
|
|
*/ |
61
|
|
|
protected $quantity; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var int|null |
65
|
|
|
* |
66
|
|
|
* @ORM\Column(nullable=true, type="integer") |
67
|
|
|
*/ |
68
|
|
|
protected $totalPrice; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var int|null |
72
|
|
|
* |
73
|
|
|
* @ORM\Column(nullable=true, type="integer") |
74
|
|
|
*/ |
75
|
|
|
protected $unitPrice; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var float|null |
79
|
|
|
* |
80
|
|
|
* @ORM\Column(nullable=true, type="decimal", precision=5, scale=2) |
81
|
|
|
*/ |
82
|
|
|
protected $vatPct; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var string|null |
86
|
|
|
* |
87
|
|
|
* @ORM\Column(nullable=true, type="string", length=191) |
88
|
|
|
*/ |
89
|
|
|
protected $variant; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var string|null |
93
|
|
|
* |
94
|
|
|
* @ORM\Column(nullable=true, type="text") |
95
|
|
|
*/ |
96
|
|
|
protected $xmlParams; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var Order |
100
|
|
|
* |
101
|
|
|
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false) |
102
|
|
|
* @ORM\ManyToOne(inversedBy="orderLines", targetEntity="Order") |
103
|
|
|
*/ |
104
|
|
|
protected $order; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var Product|null |
108
|
|
|
* |
109
|
|
|
* @ORM\JoinColumn(onDelete="SET NULL") |
110
|
|
|
* @ORM\ManyToOne(targetEntity="Product") |
111
|
|
|
*/ |
112
|
|
|
protected $product; |
113
|
|
|
|
114
|
|
|
// @todo implement withVat and withoutVat methods |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return int |
118
|
|
|
*/ |
119
|
|
|
public function getId(): int |
120
|
|
|
{ |
121
|
|
|
return (int)$this->id; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param int $id |
126
|
|
|
* @return OrderLine |
127
|
|
|
*/ |
128
|
|
|
public function setId(int $id) |
129
|
|
|
{ |
130
|
|
|
$this->id = $id; |
131
|
|
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return int |
136
|
|
|
*/ |
137
|
|
|
public function getExternalId(): int |
138
|
|
|
{ |
139
|
|
|
return $this->externalId; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param int $externalId |
144
|
|
|
* @return OrderLine |
145
|
|
|
*/ |
146
|
|
|
public function setExternalId(int $externalId) |
147
|
|
|
{ |
148
|
|
|
$this->externalId = $externalId; |
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return null|string |
154
|
|
|
*/ |
155
|
|
|
public function getFileUrl() |
156
|
|
|
{ |
157
|
|
|
return $this->fileUrl; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param null|string $fileUrl |
162
|
|
|
* @return OrderLine |
163
|
|
|
*/ |
164
|
|
|
public function setFileUrl($fileUrl) |
165
|
|
|
{ |
166
|
|
|
$this->fileUrl = $fileUrl; |
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return int|null |
172
|
|
|
*/ |
173
|
|
|
public function getProductNumber() |
174
|
|
|
{ |
175
|
|
|
return $this->productNumber; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param int|null $productNumber |
180
|
|
|
* @return OrderLine |
181
|
|
|
*/ |
182
|
|
|
public function setProductNumber($productNumber) |
183
|
|
|
{ |
184
|
|
|
$this->productNumber = $productNumber; |
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return null|string |
190
|
|
|
*/ |
191
|
|
|
public function getProductName() |
192
|
|
|
{ |
193
|
|
|
return $this->productName; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param null|string $productName |
198
|
|
|
* @return OrderLine |
199
|
|
|
*/ |
200
|
|
|
public function setProductName($productName) |
201
|
|
|
{ |
202
|
|
|
$this->productName = $productName; |
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return int|null |
208
|
|
|
*/ |
209
|
|
|
public function getQuantity() |
210
|
|
|
{ |
211
|
|
|
return $this->quantity; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param int|null $quantity |
216
|
|
|
* @return OrderLine |
217
|
|
|
*/ |
218
|
|
|
public function setQuantity($quantity) |
219
|
|
|
{ |
220
|
|
|
$this->quantity = $quantity; |
221
|
|
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @return Money|null |
226
|
|
|
*/ |
227
|
|
|
public function getTotalPrice() |
228
|
|
|
{ |
229
|
|
|
return DandomainFoundation\createMoney((string)$this->getOrder()->getCurrencyCode(), (int)$this->totalPrice); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param Money|null $totalPrice |
234
|
|
|
* @return OrderLine |
235
|
|
|
*/ |
236
|
|
|
public function setTotalPrice(Money $totalPrice = null) |
237
|
|
|
{ |
238
|
|
|
$this->totalPrice = $totalPrice ? $totalPrice->getAmount() : $totalPrice; |
|
|
|
|
239
|
|
|
|
240
|
|
|
return $this; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @return Money|null |
245
|
|
|
*/ |
246
|
|
|
public function getUnitPrice() |
247
|
|
|
{ |
248
|
|
|
return DandomainFoundation\createMoney((string)$this->getOrder()->getCurrencyCode(), (int)$this->unitPrice); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param Money|null $unitPrice |
253
|
|
|
* @return OrderLine |
254
|
|
|
*/ |
255
|
|
|
public function setUnitPrice(Money $unitPrice = null) |
256
|
|
|
{ |
257
|
|
|
$this->unitPrice = $unitPrice ? $unitPrice->getAmount() : $unitPrice; |
|
|
|
|
258
|
|
|
return $this; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @return float|null |
263
|
|
|
*/ |
264
|
|
|
public function getVatPct() |
265
|
|
|
{ |
266
|
|
|
return $this->vatPct; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @param float|null $vatPct |
271
|
|
|
* @return OrderLine |
272
|
|
|
*/ |
273
|
|
|
public function setVatPct($vatPct) |
274
|
|
|
{ |
275
|
|
|
$this->vatPct = $vatPct; |
276
|
|
|
return $this; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @return null|string |
281
|
|
|
*/ |
282
|
|
|
public function getVariant() |
283
|
|
|
{ |
284
|
|
|
return $this->variant; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param null|string $variant |
289
|
|
|
* @return OrderLine |
290
|
|
|
*/ |
291
|
|
|
public function setVariant($variant) |
292
|
|
|
{ |
293
|
|
|
$this->variant = $variant; |
294
|
|
|
return $this; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @return null|string |
299
|
|
|
*/ |
300
|
|
|
public function getXmlParams() |
301
|
|
|
{ |
302
|
|
|
return $this->xmlParams; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @param null|string $xmlParams |
307
|
|
|
* @return OrderLine |
308
|
|
|
*/ |
309
|
|
|
public function setXmlParams($xmlParams) |
310
|
|
|
{ |
311
|
|
|
$this->xmlParams = $xmlParams; |
312
|
|
|
return $this; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @return Order |
317
|
|
|
*/ |
318
|
|
|
public function getOrder(): Order |
319
|
|
|
{ |
320
|
|
|
return $this->order; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @param Order $order |
325
|
|
|
* @return OrderLine |
326
|
|
|
*/ |
327
|
|
|
public function setOrder(Order $order) |
328
|
|
|
{ |
329
|
|
|
$this->order = $order; |
330
|
|
|
return $this; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* @return Product|null |
335
|
|
|
*/ |
336
|
|
|
public function getProduct() |
337
|
|
|
{ |
338
|
|
|
return $this->product; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @param Product|null $product |
343
|
|
|
* @return OrderLine |
344
|
|
|
*/ |
345
|
|
|
public function setProduct($product) |
346
|
|
|
{ |
347
|
|
|
$this->product = $product; |
348
|
|
|
return $this; |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.