Completed
Push — master ( 256f7a...476c16 )
by Joachim
06:08
created

Order::hydrate()   B

Complexity

Conditions 8
Paths 128

Size

Total Lines 33
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 8

Importance

Changes 0
Metric Value
cc 8
eloc 16
c 0
b 0
f 0
nc 128
nop 3
dl 0
loc 33
ccs 17
cts 17
cp 1
crap 8
rs 8.2111
1
<?php
2
3
namespace Loevgaard\DandomainFoundation\Entity;
4
5
use Brick\Math\BigDecimal;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\ORM\Mapping as ORM;
8
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletable;
9
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;
10
use Loevgaard\DandomainFoundation;
11
use Loevgaard\DandomainFoundation\Entity\Generated\CurrencyInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...rated\CurrencyInterface 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...
12
use Loevgaard\DandomainFoundation\Entity\Generated\CustomerInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...rated\CustomerInterface 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...
13
use Loevgaard\DandomainFoundation\Entity\Generated\DeliveryInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...rated\DeliveryInterface 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...
14
use Loevgaard\DandomainFoundation\Entity\Generated\InvoiceInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...erated\InvoiceInterface 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...
15
use Loevgaard\DandomainFoundation\Entity\Generated\OrderInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...enerated\OrderInterface 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...
16
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...
17
use Loevgaard\DandomainFoundation\Entity\Generated\OrderTrait;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...ty\Generated\OrderTrait 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...
18
use Loevgaard\DandomainFoundation\Entity\Generated\PaymentMethodInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...\PaymentMethodInterface 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...
19
use Loevgaard\DandomainFoundation\Entity\Generated\ShippingMethodInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...ShippingMethodInterface 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...
20
use Loevgaard\DandomainFoundation\Entity\Generated\SiteInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...Generated\SiteInterface 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...
21
use Loevgaard\DandomainFoundation\Entity\Generated\StateInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...enerated\StateInterface 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...
22
use Money\Money;
23
24
/**
25
 * We use the Money library for amounts, and we use a shared currency, namely the property $currencyCode.
26
 *
27
 * @ORM\Entity()
28
 * @ORM\Table(name="ldf_orders", uniqueConstraints={
29
 *     @ORM\UniqueConstraint(name="external_id", columns={"external_id"})
30
 * })
31
 */
32
class Order extends AbstractEntity implements OrderInterface
33
{
34
    use OrderTrait;
35
    use Timestampable;
36
    use SoftDeletable;
37
38
    protected $hydrateConversions = [
39
        'id' => 'externalId',
40
    ];
41
42
    /**
43
     * @var int
44
     *
45
     * @ORM\Id
46
     * @ORM\GeneratedValue
47
     * @ORM\Column(type="integer")
48
     **/
49
    protected $id;
50
51
    /**
52
     * This is the order id in Dandomain.
53
     *
54
     * @var int
55
     *
56
     * @ORM\Column(type="integer")
57
     */
58
    protected $externalId;
59
60
    /**
61
     * @var CustomerInterface|null
62
     *
63
     * @ORM\JoinColumn(onDelete="SET NULL")
64
     * @ORM\ManyToOne(targetEntity="Customer", cascade={"persist", "remove"})
65
     */
66
    protected $customer;
67
68
    /**
69
     * @var DeliveryInterface|null
70
     *
71
     * @ORM\JoinColumn(onDelete="SET NULL")
72
     * @ORM\ManyToOne(targetEntity="Delivery", cascade={"persist", "remove"})
73
     */
74
    protected $delivery;
75
76
    /**
77
     * @var InvoiceInterface|null
78
     *
79
     * @ORM\JoinColumn(onDelete="SET NULL")
80
     * @ORM\ManyToOne(targetEntity="Invoice", cascade={"persist", "remove"})
81
     */
82
    protected $invoice;
83
84
    /**
85
     * @var OrderLineInterface[]|ArrayCollection
86
     *
87
     * @ORM\OneToMany(mappedBy="order", targetEntity="OrderLine", cascade={"persist", "remove"}, orphanRemoval=true)
88
     */
89
    protected $orderLines;
90
91
    /**
92
     * @var PaymentMethodInterface|null
93
     *
94
     * @ORM\JoinColumn(onDelete="SET NULL")
95
     * @ORM\ManyToOne(targetEntity="PaymentMethod", cascade={"persist", "remove"})
96
     */
97
    protected $paymentMethod;
98
99
    /**
100
     * Because the fee can change on the payment method we have a field for here for the fee on this order.
101
     *
102
     * @var int|null
103
     *
104
     * @ORM\Column(type="integer", nullable=true)
105
     */
106
    protected $paymentMethodFee;
107
108
    /**
109
     * @var ShippingMethodInterface|null
110
     *
111
     * @ORM\JoinColumn(onDelete="SET NULL")
112
     * @ORM\ManyToOne(targetEntity="ShippingMethod", cascade={"persist", "remove"})
113
     */
114
    protected $shippingMethod;
115
116
    /**
117
     * Because the fee can change on the shipping method we have a field for here for the fee on this order.
118
     *
119
     * @var int|null
120
     *
121
     * @ORM\Column(type="integer", nullable=true)
122
     */
123
    protected $shippingMethodFee;
124
125
    /**
126
     * @var SiteInterface|null
127
     *
128
     * @ORM\JoinColumn(onDelete="SET NULL")
129
     * @ORM\ManyToOne(targetEntity="Site", cascade={"persist", "remove"})
130
     */
131
    protected $site;
132
133
    /**
134
     * @var StateInterface|null
135
     *
136
     * @ORM\JoinColumn(onDelete="SET NULL")
137
     * @ORM\ManyToOne(targetEntity="State", cascade={"persist", "remove"})
138
     */
139
    protected $state;
140
141
    /**
142
     * @var string|null
143
     *
144
     * @ORM\Column(nullable=true, type="text")
145
     */
146
    protected $comment;
147
148
    /**
149
     * @var \DateTimeImmutable|null
150
     *
151
     * @ORM\Column(nullable=true, type="datetime_immutable", options={"comment"="Created info from Dandomain"})
152
     */
153
    protected $createdDate;
154
155
    /**
156
     * @var string|null
157
     *
158
     * @ORM\Column(nullable=true, type="string", length=191)
159
     */
160
    protected $creditNoteNumber;
161
162
    /**
163
     * The currency code in the Dandomain API refers in fact to the currencies' field named 'id' or 'code'
164
     * Therefore we don't have a currencyCode property, but a currency property.
165
     *
166
     * @var CurrencyInterface|null
167
     *
168
     * @ORM\ManyToOne(targetEntity="Currency")
169
     * @ORM\JoinColumn(nullable=false)
170
     */
171
    protected $currency;
172
173
    /**
174
     * @var string|null
175
     *
176
     * @ORM\Column(nullable=true, type="text")
177
     */
178
    protected $customerComment;
179
180
    /**
181
     * @var int|null
182
     *
183
     * @ORM\Column(type="integer", nullable=true)
184
     */
185
    protected $giftCertificateAmount;
186
187
    /**
188
     * @var string|null
189
     *
190
     * @ORM\Column(nullable=true, type="string", length=191)
191
     */
192
    protected $giftCertificateNumber;
193
194
    /**
195
     * @var bool|null
196
     *
197
     * @ORM\Column(type="boolean", nullable=true)
198
     */
199
    protected $incomplete;
200
201
    /**
202
     * @var string|null
203
     *
204
     * @ORM\Column(nullable=true, type="string", length=191)
205
     */
206
    protected $ip;
207
208
    /**
209
     * @var bool|null
210
     *
211
     * @ORM\Column(type="boolean", nullable=true)
212
     */
213
    protected $modified;
214
215
    /**
216
     * @var \DateTimeImmutable|null
217
     *
218
     * @ORM\Column(nullable=true, type="datetime_immutable", options={"comment"="Modified info from Dandomain"})
219
     */
220
    protected $modifiedDate;
221
222
    /**
223
     * @var string|null
224
     *
225
     * @ORM\Column(nullable=true, type="string", length=191)
226
     */
227
    protected $referenceNumber;
228
229
    /**
230
     * @var string|null
231
     *
232
     * @ORM\Column(nullable=true, type="text")
233
     */
234
    protected $referrer;
235
236
    /**
237
     * @var string|null
238
     *
239
     * @ORM\Column(nullable=true, type="string", length=191)
240
     */
241
    protected $reservedField1;
242
243
    /**
244
     * @var string|null
245
     *
246
     * @ORM\Column(nullable=true, type="string", length=191)
247
     */
248
    protected $reservedField2;
249
250
    /**
251
     * @var string|null
252
     *
253
     * @ORM\Column(nullable=true, type="string", length=191)
254
     */
255
    protected $reservedField3;
256
257
    /**
258
     * @var string|null
259
     *
260
     * @ORM\Column(nullable=true, type="string", length=191)
261
     */
262
    protected $reservedField4;
263
264
    /**
265
     * @var string|null
266
     *
267
     * @ORM\Column(nullable=true, type="string", length=191)
268
     */
269
    protected $reservedField5;
270
271
    /**
272
     * @var int|null
273
     *
274
     * @ORM\Column(type="integer", nullable=true)
275
     */
276
    protected $salesDiscount;
277
278
    /**
279
     * This price is incl vat.
280
     *
281
     * @var int|null
282
     *
283
     * @ORM\Column(type="integer", nullable=true)
284
     */
285
    protected $totalPrice;
286
287
    /**
288
     * @var float|null
289
     *
290
     * @ORM\Column(nullable=true, type="decimal", precision=12, scale=2)
291
     */
292
    protected $totalWeight;
293
294
    /**
295
     * @var string|null
296
     *
297
     * @ORM\Column(nullable=true, type="string", length=191)
298
     */
299
    protected $trackingNumber;
300
301
    /**
302
     * @var int|null
303
     *
304
     * @ORM\Column(nullable=true, type="string", length=191)
305
     */
306
    protected $transactionNumber;
307
308
    /**
309
     * @var float|null
310
     *
311
     * @ORM\Column(nullable=true, type="decimal", precision=5, scale=2)
312
     */
313
    protected $vatPct;
314
315
    /**
316
     * @var string|null
317
     *
318
     * @ORM\Column(nullable=true, type="string", length=191)
319
     */
320
    protected $vatRegNumber;
321
322
    /**
323
     * @var string|null
324
     *
325
     * @ORM\Column(nullable=true, type="text")
326
     */
327
    protected $xmlParams;
328
329 33
    public function __construct()
330
    {
331 33
        $this->orderLines = new ArrayCollection();
332 33
    }
333
334 3
    public function hydrate(array $data, bool $useConversions = false, $scalarsOnly = true)
335
    {
336 3
        $currency = $data['currencyCode'];
337
338 3
        if (isset($data['totalPrice'])) {
339 3
            $data['totalPrice'] = DandomainFoundation\createMoneyFromFloat($currency, $data['totalPrice']);
0 ignored issues
show
Bug introduced by
The function createMoneyFromFloat was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

339
            $data['totalPrice'] = /** @scrutinizer ignore-call */ DandomainFoundation\createMoneyFromFloat($currency, $data['totalPrice']);
Loading history...
340
        }
341
342 3
        if (isset($data['giftCertificateAmount'])) {
343 3
            $data['giftCertificateAmount'] = DandomainFoundation\createMoneyFromFloat($currency, $data['giftCertificateAmount']);
344
        }
345
346 3
        if (isset($data['salesDiscount'])) {
347 3
            $data['salesDiscount'] = DandomainFoundation\createMoneyFromFloat($currency, $data['salesDiscount']);
348
        }
349
350 3
        if (isset($data['paymentInfo']['fee'])) {
351 3
            $data['paymentMethodFee'] = DandomainFoundation\createMoneyFromFloat($currency, $data['paymentInfo']['fee']);
352
        }
353
354 3
        if (isset($data['shippingInfo']['fee'])) {
355 3
            $data['shippingMethodFee'] = DandomainFoundation\createMoneyFromFloat($currency, $data['shippingInfo']['fee']);
356
        }
357
358 3
        if ($data['createdDate']) {
359 3
            $data['createdDate'] = $this->getDateTimeFromJson($data['createdDate']);
360
        }
361
362 3
        if ($data['modifiedDate']) {
363 3
            $data['modifiedDate'] = $this->getDateTimeFromJson($data['modifiedDate']);
364
        }
365
366 3
        parent::hydrate($data, $useConversions, $scalarsOnly);
367 3
    }
368
369
    /*
370
     * Helper methods
371
     */
372
    public function getTotalPriceInclVat(): ?Money
373
    {
374
        return $this->getTotalPrice();
375
    }
376
377
    public function getTotalPriceExclVat(): ?Money
378
    {
379
        $totalPrice = $this->getTotalPrice();
380
        if (!$totalPrice) {
381
            return null;
382
        }
383
384
        $multiplier = BigDecimal::of('100')->exactlyDividedBy(BigDecimal::of('100')->plus($this->vatPct));
0 ignored issues
show
Bug introduced by
The method exactlyDividedBy() does not exist on Brick\Math\BigRational. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

384
        $multiplier = BigDecimal::of('100')->/** @scrutinizer ignore-call */ exactlyDividedBy(BigDecimal::of('100')->plus($this->vatPct));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method exactlyDividedBy() does not exist on Brick\Math\BigInteger. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

384
        $multiplier = BigDecimal::of('100')->/** @scrutinizer ignore-call */ exactlyDividedBy(BigDecimal::of('100')->plus($this->vatPct));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
385
386
        return $totalPrice->multiply((string) $multiplier);
387
    }
388
389
    public function totalPriceWithoutFees(): ?Money
390
    {
391
        $totalPrice = $this->getTotalPrice();
392
        if (!$totalPrice) {
393
            return null;
394
        }
395
396
        $paymentMethodFee = $this->getPaymentMethodFee();
397
        if ($paymentMethodFee) {
398
            $totalPrice = $totalPrice->subtract($paymentMethodFee);
399
        }
400
401
        $shippingMethodFee = $this->getShippingMethodFee();
402
        if ($shippingMethodFee) {
403
            $totalPrice = $totalPrice->subtract($shippingMethodFee);
404
        }
405
406
        return $totalPrice;
407
    }
408
409
    /*
410
     * Collection methods
411
     */
412 15
    public function addOrderLine(OrderLineInterface $orderLine): OrderInterface
413
    {
414 15
        if (!$this->hasOrderLine($orderLine)) {
415 15
            $this->orderLines->add($orderLine);
416 15
            $orderLine->setOrder($this);
417
        }
418
419 15
        return $this;
420
    }
421
422
    /**
423
     * @param OrderLineInterface|int $orderLine Either the OrderLineInterface or the external id
424
     *
425
     * @return bool
426
     */
427 15
    public function hasOrderLine($orderLine): bool
428
    {
429 15
        if ($orderLine instanceof OrderLineInterface) {
430 15
            $orderLine = $orderLine->getExternalId();
431
        }
432
433 15
        return $this->orderLines->exists(function ($key, OrderLineInterface $element) use ($orderLine) {
434 9
            return $element->getExternalId() === $orderLine;
435 15
        });
436
    }
437
438 3
    public function removeOrderLine(OrderLineInterface $orderLine): OrderInterface
439
    {
440 3
        $orderLine->setOrder(null);
441 3
        $this->orderLines->removeElement($orderLine);
442
443 3
        return $this;
444
    }
445
446 3
    public function clearOrderLines(): OrderInterface
447
    {
448 3
        foreach ($this->orderLines as $orderLine) {
449 3
            $orderLine->setOrder(null);
450
        }
451
452 3
        $this->orderLines->clear();
453
454 3
        return $this;
455
    }
456
457
    /**
458
     * @param OrderLineInterface[] $orderLines
459
     */
460
    public function updateOrderLines(array $orderLines): void
461
    {
462
        // this holds the final array of order lines, whether updated or added
463
        $final = [];
464
        foreach ($orderLines as $orderLine) {
465
            $existing = $this->findOrderLine($orderLine);
466
            if ($existing) {
467
                $existing->copyProperties($orderLine);
468
                $existing->setOrder($this);
469
                $final[] = $existing;
470
            } else {
471
                $this->addOrderLine($orderLine);
472
                $final[] = $orderLine;
473
            }
474
        }
475
476
        foreach ($this->orderLines as $orderLine) {
477
            if (!in_array($orderLine, $final, true)) {
478
                $this->removeOrderLine($orderLine);
479
            }
480
        }
481
    }
482
483
    /*
484
     * Getters / Setters
485
     */
486
487
    /**
488
     * @return Money|null
489
     */
490 3
    public function getTotalPrice(): ?Money
491
    {
492 3
        return $this->createMoney((int) $this->totalPrice);
493
    }
494
495
    /**
496
     * @param Money $money
497
     *
498
     * @return OrderInterface
499
     */
500 3
    public function setTotalPrice(Money $money = null): OrderInterface
501
    {
502 3
        $this->totalPrice = $money->getAmount();
0 ignored issues
show
Bug introduced by
The method getAmount() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

502
        /** @scrutinizer ignore-call */ 
503
        $this->totalPrice = $money->getAmount();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Documentation Bug introduced by
It seems like $money->getAmount() of type string is incompatible with the declared type integer|null of property $totalPrice.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
503
504 3
        return $this;
505
    }
506
507
    /**
508
     * @return Money|null
509
     */
510 3
    public function getSalesDiscount(): ?Money
511
    {
512 3
        return $this->createMoney((int) $this->salesDiscount);
513
    }
514
515
    /**
516
     * @param Money $money
517
     *
518
     * @return OrderInterface
519
     */
520 3
    public function setSalesDiscount(Money $money = null): OrderInterface
521
    {
522 3
        $this->salesDiscount = $money->getAmount();
0 ignored issues
show
Documentation Bug introduced by
It seems like $money->getAmount() of type string is incompatible with the declared type integer|null of property $salesDiscount.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
523
524 3
        return $this;
525
    }
526
527
    /**
528
     * @return Money|null
529
     */
530 3
    public function getGiftCertificateAmount(): ?Money
531
    {
532 3
        return $this->createMoney((int) $this->giftCertificateAmount);
533
    }
534
535
    /**
536
     * @param Money $money
537
     *
538
     * @return OrderInterface
539
     */
540 3
    public function setGiftCertificateAmount(Money $money = null): OrderInterface
541
    {
542 3
        $this->giftCertificateAmount = $money->getAmount();
0 ignored issues
show
Documentation Bug introduced by
It seems like $money->getAmount() of type string is incompatible with the declared type integer|null of property $giftCertificateAmount.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
543
544 3
        return $this;
545
    }
546
547
    /**
548
     * @return Money|null
549
     */
550 3
    public function getShippingMethodFee(): ?Money
551
    {
552 3
        return $this->createMoney((int) $this->shippingMethodFee);
553
    }
554
555
    /**
556
     * @param Money $money
557
     *
558
     * @return OrderInterface
559
     */
560 3
    public function setShippingMethodFee(Money $money = null): OrderInterface
561
    {
562 3
        $this->shippingMethodFee = $money->getAmount();
0 ignored issues
show
Documentation Bug introduced by
It seems like $money->getAmount() of type string is incompatible with the declared type integer|null of property $shippingMethodFee.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
563
564 3
        return $this;
565
    }
566
567
    /**
568
     * @return Money|null
569
     */
570 3
    public function getPaymentMethodFee(): ?Money
571
    {
572 3
        return $this->createMoney((int) $this->paymentMethodFee);
573
    }
574
575
    /**
576
     * @param Money $money
577
     *
578
     * @return OrderInterface
579
     */
580 3
    public function setPaymentMethodFee(Money $money = null): OrderInterface
581
    {
582 3
        $this->paymentMethodFee = $money->getAmount();
0 ignored issues
show
Documentation Bug introduced by
It seems like $money->getAmount() of type string is incompatible with the declared type integer|null of property $paymentMethodFee.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
583
584 3
        return $this;
585
    }
586
587
    /**
588
     * @return int
589
     */
590 6
    public function getId(): int
591
    {
592 6
        return (int) $this->id;
593
    }
594
595
    /**
596
     * @param int $id
597
     *
598
     * @return OrderInterface
599
     */
600 3
    public function setId($id)
601
    {
602 3
        $this->id = $id;
603
604 3
        return $this;
605
    }
606
607
    /**
608
     * @return int
609
     */
610 6
    public function getExternalId(): int
611
    {
612 6
        return (int) $this->externalId;
613
    }
614
615
    /**
616
     * @param int $externalId
617
     *
618
     * @return OrderInterface
619
     */
620 3
    public function setExternalId($externalId)
621
    {
622 3
        $this->externalId = $externalId;
623
624 3
        return $this;
625
    }
626
627
    /**
628
     * @return CustomerInterface|null
629
     */
630 3
    public function getCustomer()
631
    {
632 3
        return $this->customer;
633
    }
634
635
    /**
636
     * @param CustomerInterface|null $customer
637
     *
638
     * @return OrderInterface
639
     */
640 3
    public function setCustomer($customer)
641
    {
642 3
        $this->customer = $customer;
643
644 3
        return $this;
645
    }
646
647
    /**
648
     * @return DeliveryInterface|null
649
     */
650 3
    public function getDelivery()
651
    {
652 3
        return $this->delivery;
653
    }
654
655
    /**
656
     * @param DeliveryInterface|null $delivery
657
     *
658
     * @return OrderInterface
659
     */
660 3
    public function setDelivery($delivery)
661
    {
662 3
        $this->delivery = $delivery;
663
664 3
        return $this;
665
    }
666
667
    /**
668
     * @return InvoiceInterface|null
669
     */
670 3
    public function getInvoice()
671
    {
672 3
        return $this->invoice;
673
    }
674
675
    /**
676
     * @param InvoiceInterface|null $invoice
677
     *
678
     * @return OrderInterface
679
     */
680 3
    public function setInvoice($invoice)
681
    {
682 3
        $this->invoice = $invoice;
683
684 3
        return $this;
685
    }
686
687
    /**
688
     * @return ArrayCollection|OrderLineInterface[]
689
     */
690 12
    public function getOrderLines()
691
    {
692 12
        return $this->orderLines;
693
    }
694
695
    /**
696
     * @param ArrayCollection|null $orderLines
697
     *
698
     * @return OrderInterface
699
     */
700 3
    public function setOrderLines($orderLines)
701
    {
702 3
        $this->orderLines = $orderLines;
703
704 3
        return $this;
705
    }
706
707
    /**
708
     * @return PaymentMethodInterface|null
709
     */
710 3
    public function getPaymentMethod()
711
    {
712 3
        return $this->paymentMethod;
713
    }
714
715
    /**
716
     * @param PaymentMethodInterface|null $paymentMethod
717
     *
718
     * @return OrderInterface
719
     */
720 3
    public function setPaymentMethod($paymentMethod)
721
    {
722 3
        $this->paymentMethod = $paymentMethod;
723
724 3
        return $this;
725
    }
726
727
    /**
728
     * @return ShippingMethodInterface|null
729
     */
730 3
    public function getShippingMethod()
731
    {
732 3
        return $this->shippingMethod;
733
    }
734
735
    /**
736
     * @param ShippingMethodInterface|null $shippingMethod
737
     *
738
     * @return OrderInterface
739
     */
740 3
    public function setShippingMethod($shippingMethod)
741
    {
742 3
        $this->shippingMethod = $shippingMethod;
743
744 3
        return $this;
745
    }
746
747
    /**
748
     * @return SiteInterface|null
749
     */
750 3
    public function getSite()
751
    {
752 3
        return $this->site;
753
    }
754
755
    /**
756
     * @param SiteInterface|null $site
757
     *
758
     * @return OrderInterface
759
     */
760 3
    public function setSite($site)
761
    {
762 3
        $this->site = $site;
763
764 3
        return $this;
765
    }
766
767
    /**
768
     * @return StateInterface|null
769
     */
770 3
    public function getState()
771
    {
772 3
        return $this->state;
773
    }
774
775
    /**
776
     * @param StateInterface|null $state
777
     *
778
     * @return OrderInterface
779
     */
780 3
    public function setState($state)
781
    {
782 3
        $this->state = $state;
783
784 3
        return $this;
785
    }
786
787
    /**
788
     * @return null|string
789
     */
790 3
    public function getComment()
791
    {
792 3
        return $this->comment;
793
    }
794
795
    /**
796
     * @param null|string $comment
797
     *
798
     * @return OrderInterface
799
     */
800 3
    public function setComment($comment)
801
    {
802 3
        $this->comment = $comment;
803
804 3
        return $this;
805
    }
806
807
    /**
808
     * @return \DateTimeImmutable|null
809
     */
810 3
    public function getCreatedDate()
811
    {
812 3
        return $this->createdDate;
813
    }
814
815
    /**
816
     * @param \DateTimeImmutable|null $createdDate
817
     *
818
     * @return OrderInterface
819
     */
820 3
    public function setCreatedDate($createdDate)
821
    {
822 3
        $this->createdDate = $createdDate;
823
824 3
        return $this;
825
    }
826
827
    /**
828
     * @return null|string
829
     */
830 3
    public function getCreditNoteNumber()
831
    {
832 3
        return $this->creditNoteNumber;
833
    }
834
835
    /**
836
     * @param null|string $creditNoteNumber
837
     *
838
     * @return Order
839
     */
840 3
    public function setCreditNoteNumber($creditNoteNumber)
841
    {
842 3
        $this->creditNoteNumber = $creditNoteNumber;
843
844 3
        return $this;
845
    }
846
847
    /**
848
     * @return CurrencyInterface|null
849
     */
850 9
    public function getCurrency()
851
    {
852 9
        return $this->currency;
853
    }
854
855
    /**
856
     * @param null|CurrencyInterface $currency
857
     *
858
     * @return OrderInterface
859
     */
860 12
    public function setCurrency($currency)
861
    {
862 12
        $this->currency = $currency;
863
864 12
        return $this;
865
    }
866
867
    /**
868
     * @return null|string
869
     */
870 3
    public function getCustomerComment()
871
    {
872 3
        return $this->customerComment;
873
    }
874
875
    /**
876
     * @param null|string $customerComment
877
     *
878
     * @return OrderInterface
879
     */
880 3
    public function setCustomerComment($customerComment)
881
    {
882 3
        $this->customerComment = $customerComment;
883
884 3
        return $this;
885
    }
886
887
    /**
888
     * @return null|string
889
     */
890 3
    public function getGiftCertificateNumber()
891
    {
892 3
        return $this->giftCertificateNumber;
893
    }
894
895
    /**
896
     * @param null|string $giftCertificateNumber
897
     *
898
     * @return OrderInterface
899
     */
900 3
    public function setGiftCertificateNumber($giftCertificateNumber)
901
    {
902 3
        $this->giftCertificateNumber = $giftCertificateNumber;
903
904 3
        return $this;
905
    }
906
907
    /**
908
     * @return bool|null
909
     */
910 3
    public function getIncomplete()
911
    {
912 3
        return $this->incomplete;
913
    }
914
915
    /**
916
     * @param bool|null $incomplete
917
     *
918
     * @return OrderInterface
919
     */
920 3
    public function setIncomplete($incomplete)
921
    {
922 3
        $this->incomplete = $incomplete;
923
924 3
        return $this;
925
    }
926
927
    /**
928
     * @return null|string
929
     */
930 3
    public function getIp()
931
    {
932 3
        return $this->ip;
933
    }
934
935
    /**
936
     * @param null|string $ip
937
     *
938
     * @return OrderInterface
939
     */
940 3
    public function setIp($ip)
941
    {
942 3
        $this->ip = $ip;
943
944 3
        return $this;
945
    }
946
947
    /**
948
     * @return bool|null
949
     */
950 3
    public function getModified()
951
    {
952 3
        return $this->modified;
953
    }
954
955
    /**
956
     * @param bool|null $modified
957
     *
958
     * @return OrderInterface
959
     */
960 3
    public function setModified($modified)
961
    {
962 3
        $this->modified = $modified;
963
964 3
        return $this;
965
    }
966
967
    /**
968
     * @return \DateTimeImmutable|null
969
     */
970 3
    public function getModifiedDate()
971
    {
972 3
        return $this->modifiedDate;
973
    }
974
975
    /**
976
     * @param \DateTimeImmutable|null $modifiedDate
977
     *
978
     * @return OrderInterface
979
     */
980 3
    public function setModifiedDate($modifiedDate)
981
    {
982 3
        $this->modifiedDate = $modifiedDate;
983
984 3
        return $this;
985
    }
986
987
    /**
988
     * @return null|string
989
     */
990 3
    public function getReferenceNumber()
991
    {
992 3
        return $this->referenceNumber;
993
    }
994
995
    /**
996
     * @param null|string $referenceNumber
997
     *
998
     * @return OrderInterface
999
     */
1000 3
    public function setReferenceNumber($referenceNumber)
1001
    {
1002 3
        $this->referenceNumber = $referenceNumber;
1003
1004 3
        return $this;
1005
    }
1006
1007
    /**
1008
     * @return null|string
1009
     */
1010 3
    public function getReferrer()
1011
    {
1012 3
        return $this->referrer;
1013
    }
1014
1015
    /**
1016
     * @param null|string $referrer
1017
     *
1018
     * @return OrderInterface
1019
     */
1020 3
    public function setReferrer($referrer)
1021
    {
1022 3
        $this->referrer = $referrer;
1023
1024 3
        return $this;
1025
    }
1026
1027
    /**
1028
     * @return null|string
1029
     */
1030 3
    public function getReservedField1()
1031
    {
1032 3
        return $this->reservedField1;
1033
    }
1034
1035
    /**
1036
     * @param null|string $reservedField1
1037
     *
1038
     * @return OrderInterface
1039
     */
1040 3
    public function setReservedField1($reservedField1)
1041
    {
1042 3
        $this->reservedField1 = $reservedField1;
1043
1044 3
        return $this;
1045
    }
1046
1047
    /**
1048
     * @return null|string
1049
     */
1050 3
    public function getReservedField2()
1051
    {
1052 3
        return $this->reservedField2;
1053
    }
1054
1055
    /**
1056
     * @param null|string $reservedField2
1057
     *
1058
     * @return OrderInterface
1059
     */
1060 3
    public function setReservedField2($reservedField2)
1061
    {
1062 3
        $this->reservedField2 = $reservedField2;
1063
1064 3
        return $this;
1065
    }
1066
1067
    /**
1068
     * @return null|string
1069
     */
1070 3
    public function getReservedField3()
1071
    {
1072 3
        return $this->reservedField3;
1073
    }
1074
1075
    /**
1076
     * @param null|string $reservedField3
1077
     *
1078
     * @return OrderInterface
1079
     */
1080 3
    public function setReservedField3($reservedField3)
1081
    {
1082 3
        $this->reservedField3 = $reservedField3;
1083
1084 3
        return $this;
1085
    }
1086
1087
    /**
1088
     * @return null|string
1089
     */
1090 3
    public function getReservedField4()
1091
    {
1092 3
        return $this->reservedField4;
1093
    }
1094
1095
    /**
1096
     * @param null|string $reservedField4
1097
     *
1098
     * @return OrderInterface
1099
     */
1100 3
    public function setReservedField4($reservedField4)
1101
    {
1102 3
        $this->reservedField4 = $reservedField4;
1103
1104 3
        return $this;
1105
    }
1106
1107
    /**
1108
     * @return null|string
1109
     */
1110 3
    public function getReservedField5()
1111
    {
1112 3
        return $this->reservedField5;
1113
    }
1114
1115
    /**
1116
     * @param null|string $reservedField5
1117
     *
1118
     * @return OrderInterface
1119
     */
1120 3
    public function setReservedField5($reservedField5)
1121
    {
1122 3
        $this->reservedField5 = $reservedField5;
1123
1124 3
        return $this;
1125
    }
1126
1127
    /**
1128
     * @return float|null
1129
     */
1130 3
    public function getTotalWeight()
1131
    {
1132 3
        return $this->totalWeight;
1133
    }
1134
1135
    /**
1136
     * @param float|null $totalWeight
1137
     *
1138
     * @return OrderInterface
1139
     */
1140 3
    public function setTotalWeight($totalWeight)
1141
    {
1142 3
        $this->totalWeight = $totalWeight;
1143
1144 3
        return $this;
1145
    }
1146
1147
    /**
1148
     * @return null|string
1149
     */
1150 3
    public function getTrackingNumber()
1151
    {
1152 3
        return $this->trackingNumber;
1153
    }
1154
1155
    /**
1156
     * @param null|string $trackingNumber
1157
     *
1158
     * @return OrderInterface
1159
     */
1160 3
    public function setTrackingNumber($trackingNumber)
1161
    {
1162 3
        $this->trackingNumber = $trackingNumber;
1163
1164 3
        return $this;
1165
    }
1166
1167
    /**
1168
     * @return int|null
1169
     */
1170 3
    public function getTransactionNumber()
1171
    {
1172 3
        return $this->transactionNumber;
1173
    }
1174
1175
    /**
1176
     * @param int|null $transactionNumber
1177
     *
1178
     * @return OrderInterface
1179
     */
1180 3
    public function setTransactionNumber($transactionNumber)
1181
    {
1182 3
        $this->transactionNumber = $transactionNumber;
1183
1184 3
        return $this;
1185
    }
1186
1187
    /**
1188
     * @return float|null
1189
     */
1190 3
    public function getVatPct()
1191
    {
1192 3
        return $this->vatPct;
1193
    }
1194
1195
    /**
1196
     * @param float|null $vatPct
1197
     *
1198
     * @return OrderInterface
1199
     */
1200 3
    public function setVatPct($vatPct)
1201
    {
1202 3
        $this->vatPct = $vatPct;
1203
1204 3
        return $this;
1205
    }
1206
1207
    /**
1208
     * @return null|string
1209
     */
1210 3
    public function getVatRegNumber()
1211
    {
1212 3
        return $this->vatRegNumber;
1213
    }
1214
1215
    /**
1216
     * @param null|string $vatRegNumber
1217
     *
1218
     * @return OrderInterface
1219
     */
1220 3
    public function setVatRegNumber($vatRegNumber)
1221
    {
1222 3
        $this->vatRegNumber = $vatRegNumber;
1223
1224 3
        return $this;
1225
    }
1226
1227
    /**
1228
     * @return null|string
1229
     */
1230 3
    public function getXmlParams()
1231
    {
1232 3
        return $this->xmlParams;
1233
    }
1234
1235
    /**
1236
     * @param null|string $xmlParams
1237
     *
1238
     * @return OrderInterface
1239
     */
1240 3
    public function setXmlParams($xmlParams)
1241
    {
1242 3
        $this->xmlParams = $xmlParams;
1243
1244 3
        return $this;
1245
    }
1246
1247
    protected function findOrderLine(OrderLineInterface $orderLine): ?OrderLineInterface
1248
    {
1249
        foreach ($this->orderLines as $ol) {
1250
            if ($orderLine->getExternalId() === $ol->getExternalId()) {
1251
                return $ol;
1252
            }
1253
        }
1254
1255
        return null;
1256
    }
1257
1258
    /**
1259
     * A helper method for creating a Money object from a float based on the shared currency.
1260
     *
1261
     * @param int $amount
1262
     *
1263
     * @return Money|null
1264
     */
1265 3
    private function createMoney(int $amount = 0): ?Money
1266
    {
1267 3
        if (!$this->currency) {
1268
            return null;
1269
        }
1270
1271 3
        return DandomainFoundation\createMoney($this->currency->getIsoCodeAlpha(), $amount);
0 ignored issues
show
Bug introduced by
The function createMoney was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1271
        return /** @scrutinizer ignore-call */ DandomainFoundation\createMoney($this->currency->getIsoCodeAlpha(), $amount);
Loading history...
1272
    }
1273
}
1274