Completed
Push — master ( ad1942...52091d )
by Joachim
15:28
created

OrderLine::hydrate()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 5
nop 3
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...ated\OrderLineInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Loevgaard\DandomainFoundation\Entity\Generated\OrderLineTrait;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...enerated\OrderLineTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Loevgaard\DandomainFoundation\Entity\Generated\ProductInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...erated\ProductInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Money\Money;
11
12
/**
13
 * @ORM\Entity()
14
 * @ORM\Table(name="ldf_order_lines")
15
 */
16
class OrderLine extends AbstractEntity implements OrderLineInterface
17
{
18
    use OrderLineTrait;
19
20
    protected $hydrateConversions = [
21
        'id' => 'externalId',
22
        'productId' => 'productNumber'
23
    ];
24
25
    /**
26
     * @var int
27
     *
28
     * @ORM\Id
29
     * @ORM\GeneratedValue
30
     * @ORM\Column(type="integer")
31
     **/
32
    protected $id;
33
34
    /**
35
     * @var int
36
     *
37
     * @ORM\Column(type="integer", unique=true)
38
     */
39
    protected $externalId;
40
41
    /**
42
     * @var string|null
43
     *
44
     * @ORM\Column(nullable=true, type="string", length=191)
45
     */
46
    protected $fileUrl;
47
48
    /**
49
     * @var int|null
50
     *
51
     * @ORM\Column(nullable=true, type="string", length=191)
52
     */
53
    protected $productNumber;
54
55
    /**
56
     * @var string|null
57
     *
58
     * @ORM\Column(nullable=true, type="string", length=191)
59
     */
60
    protected $productName;
61
62
    /**
63
     * @var int|null
64
     *
65
     * @ORM\Column(nullable=true, type="integer")
66
     */
67
    protected $quantity;
68
69
    /**
70
     * @var int|null
71
     *
72
     * @ORM\Column(nullable=true, type="integer")
73
     */
74
    protected $totalPrice;
75
76
    /**
77
     * @var int|null
78
     *
79
     * @ORM\Column(nullable=true, type="integer")
80
     */
81
    protected $unitPrice;
82
83
    /**
84
     * @var float|null
85
     *
86
     * @ORM\Column(nullable=true, type="decimal", precision=5, scale=2)
87
     */
88
    protected $vatPct;
89
90
    /**
91
     * @var string|null
92
     *
93
     * @ORM\Column(nullable=true, type="string", length=191)
94
     */
95
    protected $variant;
96
97
    /**
98
     * @var string|null
99
     *
100
     * @ORM\Column(nullable=true, type="text")
101
     */
102
    protected $xmlParams;
103
104
    /**
105
     * @var Order
106
     *
107
     * @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
108
     * @ORM\ManyToOne(inversedBy="orderLines", targetEntity="Order")
109
     */
110
    protected $order;
111
112
    /**
113
     * @var ProductInterface|null
114
     *
115
     * @ORM\JoinColumn(onDelete="SET NULL")
116
     * @ORM\ManyToOne(targetEntity="Product")
117
     */
118
    protected $product;
119
120
    // @todo implement withVat and withoutVat methods
121
122
    public function hydrate(array $data, bool $useConversions = false, $scalarsOnly = true)
123
    {
124
        if (is_null($this->order)) {
125
            throw new \RuntimeException('Cannot hydrate order line without an associated order');
126
        }
127
128
        $currency = $this->order->getCurrencyCode();
129
130
        if (isset($data['unitPrice'])) {
131
            $data['unitPrice'] = DandomainFoundation\createMoneyFromFloat($currency, $data['unitPrice']);
132
        }
133
134
        if (isset($data['totalPrice'])) {
135
            $data['totalPrice'] = DandomainFoundation\createMoneyFromFloat($currency, $data['totalPrice']);
136
        }
137
138
        parent::hydrate($data, $useConversions, $scalarsOnly);
139
    }
140
141
    /**
142
     * @return int
143
     */
144
    public function getId(): int
145
    {
146
        return (int)$this->id;
147
    }
148
149
    /**
150
     * @param int $id
151
     * @return OrderLineInterface
152
     */
153
    public function setId(int $id)
154
    {
155
        $this->id = $id;
156
        return $this;
157
    }
158
159
    /**
160
     * @return int
161
     */
162
    public function getExternalId(): int
163
    {
164
        return (int)$this->externalId;
165
    }
166
167
    /**
168
     * @param int $externalId
169
     * @return OrderLineInterface
170
     */
171
    public function setExternalId(int $externalId)
172
    {
173
        $this->externalId = $externalId;
174
        return $this;
175
    }
176
177
    /**
178
     * @return null|string
179
     */
180
    public function getFileUrl()
181
    {
182
        return $this->fileUrl;
183
    }
184
185
    /**
186
     * @param null|string $fileUrl
187
     * @return OrderLineInterface
188
     */
189
    public function setFileUrl($fileUrl)
190
    {
191
        $this->fileUrl = $fileUrl;
192
        return $this;
193
    }
194
195
    /**
196
     * @return int|null
197
     */
198
    public function getProductNumber()
199
    {
200
        return $this->productNumber;
201
    }
202
203
    /**
204
     * @param int|null $productNumber
205
     * @return OrderLineInterface
206
     */
207
    public function setProductNumber($productNumber)
208
    {
209
        $this->productNumber = $productNumber;
210
        return $this;
211
    }
212
213
    /**
214
     * @return null|string
215
     */
216
    public function getProductName()
217
    {
218
        return $this->productName;
219
    }
220
221
    /**
222
     * @param null|string $productName
223
     * @return OrderLineInterface
224
     */
225
    public function setProductName($productName)
226
    {
227
        $this->productName = $productName;
228
        return $this;
229
    }
230
231
    /**
232
     * @return int|null
233
     */
234
    public function getQuantity()
235
    {
236
        return $this->quantity;
237
    }
238
239
    /**
240
     * @param int|null $quantity
241
     * @return OrderLineInterface
242
     */
243
    public function setQuantity($quantity)
244
    {
245
        $this->quantity = $quantity;
246
        return $this;
247
    }
248
249
    /**
250
     * @return Money|null
251
     */
252
    public function getTotalPrice()
253
    {
254
        return DandomainFoundation\createMoney((string)$this->getOrder()->getCurrencyCode(), (int)$this->totalPrice);
255
    }
256
257
    /**
258
     * @param Money|null $totalPrice
259
     * @return OrderLineInterface
260
     */
261
    public function setTotalPrice(Money $totalPrice = null)
262
    {
263
        $this->totalPrice = $totalPrice ? $totalPrice->getAmount() : $totalPrice;
264
265
        return $this;
266
    }
267
268
    /**
269
     * @return Money|null
270
     */
271
    public function getUnitPrice()
272
    {
273
        return DandomainFoundation\createMoney((string)$this->getOrder()->getCurrencyCode(), (int)$this->unitPrice);
274
    }
275
276
    /**
277
     * @param Money|null $unitPrice
278
     * @return OrderLineInterface
279
     */
280
    public function setUnitPrice(Money $unitPrice = null)
281
    {
282
        $this->unitPrice = $unitPrice ? $unitPrice->getAmount() : $unitPrice;
283
        return $this;
284
    }
285
286
    /**
287
     * @return float|null
288
     */
289
    public function getVatPct()
290
    {
291
        return $this->vatPct;
292
    }
293
294
    /**
295
     * @param float|null $vatPct
296
     * @return OrderLineInterface
297
     */
298
    public function setVatPct($vatPct)
299
    {
300
        $this->vatPct = $vatPct;
301
        return $this;
302
    }
303
304
    /**
305
     * @return null|string
306
     */
307
    public function getVariant()
308
    {
309
        return $this->variant;
310
    }
311
312
    /**
313
     * @param null|string $variant
314
     * @return OrderLineInterface
315
     */
316
    public function setVariant($variant)
317
    {
318
        $this->variant = $variant;
319
        return $this;
320
    }
321
322
    /**
323
     * @return null|string
324
     */
325
    public function getXmlParams()
326
    {
327
        return $this->xmlParams;
328
    }
329
330
    /**
331
     * @param null|string $xmlParams
332
     * @return OrderLineInterface
333
     */
334
    public function setXmlParams($xmlParams)
335
    {
336
        $this->xmlParams = $xmlParams;
337
        return $this;
338
    }
339
340
    /**
341
     * @return Order
342
     */
343
    public function getOrder(): Order
344
    {
345
        return $this->order;
346
    }
347
348
    /**
349
     * @param Order|null $order
350
     * @return OrderLineInterface
351
     */
352
    public function setOrder(Order $order)
353
    {
354
        $this->order = $order;
355
        return $this;
356
    }
357
358
    /**
359
     * @return ProductInterface|null
360
     */
361
    public function getProduct()
362
    {
363
        return $this->product;
364
    }
365
366
    /**
367
     * @param ProductInterface|null $product
368
     * @return OrderLineInterface
369
     */
370
    public function setProduct(ProductInterface $product = null)
371
    {
372
        $this->product = $product;
373
        return $this;
374
    }
375
}
376