Passed
Push — master ( c4324c...02742b )
by Joachim
10:39
created

Order::updateOrderLines()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5

Importance

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

337
            $data['totalPrice'] = /** @scrutinizer ignore-call */ DandomainFoundation\createMoneyFromFloat($currency, $data['totalPrice']);
Loading history...
338 3
        }
339 3
340
        if (isset($data['giftCertificateAmount'])) {
341
            $data['giftCertificateAmount'] = DandomainFoundation\createMoneyFromFloat($currency, $data['giftCertificateAmount']);
342 3
        }
343 3
344
        if (isset($data['salesDiscount'])) {
345
            $data['salesDiscount'] = DandomainFoundation\createMoneyFromFloat($currency, $data['salesDiscount']);
346 3
        }
347 3
348
        if (isset($data['paymentInfo']['fee'])) {
349
            $data['paymentMethodFee'] = DandomainFoundation\createMoneyFromFloat($currency, $data['paymentInfo']['fee']);
350 3
        }
351 3
352
        if (isset($data['shippingInfo']['fee'])) {
353
            $data['shippingMethodFee'] = DandomainFoundation\createMoneyFromFloat($currency, $data['shippingInfo']['fee']);
354 3
        }
355 3
356
        if ($data['createdDate']) {
357
            $data['createdDate'] = $this->getDateTimeFromJson($data['createdDate']);
358 3
        }
359 3
360
        if ($data['modifiedDate']) {
361
            $data['modifiedDate'] = $this->getDateTimeFromJson($data['modifiedDate']);
362
        }
363
364
        parent::hydrate($data, $useConversions, $scalarsOnly);
365
    }
366
367
    /*
368
     * Helper methods
369
     */
370
    public function getTotalPriceInclVat() : ?Money
371
    {
372
        return $this->getTotalPrice();
373
    }
374
375
    public function getTotalPriceExclVat() : ?Money
376
    {
377
        $totalPrice = $this->getTotalPrice();
378
        if (!$totalPrice) {
379
            return null;
380
        }
381
382
        $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

382
        $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

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

497
        /** @scrutinizer ignore-call */ 
498
        $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 null|integer 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...
498 3
499
        return $this;
500 3
    }
501
502 3
    /**
503
     * @return Money|null
504
     */
505
    public function getSalesDiscount() : ?Money
506
    {
507
        return $this->createMoney((int)$this->salesDiscount);
508 3
    }
509
510 3
    /**
511
     * @param Money $money
512
     * @return OrderInterface
513
     */
514
    public function setSalesDiscount(Money $money = null) : OrderInterface
515
    {
516
        $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 null|integer 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...
517 3
518
        return $this;
519 3
    }
520
521 3
    /**
522
     * @return Money|null
523
     */
524
    public function getGiftCertificateAmount() : ?Money
525
    {
526
        return $this->createMoney((int)$this->giftCertificateAmount);
527 3
    }
528
529 3
    /**
530
     * @param Money $money
531
     * @return OrderInterface
532
     */
533
    public function setGiftCertificateAmount(Money $money = null) : OrderInterface
534
    {
535
        $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 null|integer 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...
536 3
537
        return $this;
538 3
    }
539
540 3
    /**
541
     * @return Money|null
542
     */
543
    public function getShippingMethodFee() : ?Money
544
    {
545
        return $this->createMoney((int)$this->shippingMethodFee);
546 6
    }
547
548 6
    /**
549
     * @param Money $money
550
     * @return OrderInterface
551
     */
552
    public function setShippingMethodFee(Money $money = null) : OrderInterface
553
    {
554
        $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 null|integer 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...
555 3
556
        return $this;
557 3
    }
558 3
559
    /**
560
     * @return Money|null
561
     */
562
    public function getPaymentMethodFee() : ?Money
563
    {
564 6
        return $this->createMoney((int)$this->paymentMethodFee);
565
    }
566 6
567
    /**
568
     * @param Money $money
569
     * @return OrderInterface
570
     */
571
    public function setPaymentMethodFee(Money $money = null) : OrderInterface
572
    {
573 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 null|integer 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...
574
575 3
        return $this;
576 3
    }
577
578
    /**
579
     * @return int
580
     */
581
    public function getId(): int
582 3
    {
583
        return (int)$this->id;
584 3
    }
585
586
    /**
587
     * @param int $id
588
     * @return OrderInterface
589
     */
590
    public function setId($id)
591 3
    {
592
        $this->id = $id;
593 3
        return $this;
594 3
    }
595
596
    /**
597
     * @return int
598
     */
599
    public function getExternalId(): int
600 3
    {
601
        return (int)$this->externalId;
602 3
    }
603
604
    /**
605
     * @param int $externalId
606
     * @return OrderInterface
607
     */
608
    public function setExternalId($externalId)
609 3
    {
610
        $this->externalId = $externalId;
611 3
        return $this;
612 3
    }
613
614
    /**
615
     * @return CustomerInterface|null
616
     */
617
    public function getCustomer()
618 3
    {
619
        return $this->customer;
620 3
    }
621
622
    /**
623
     * @param CustomerInterface|null $customer
624
     * @return OrderInterface
625
     */
626
    public function setCustomer($customer)
627 3
    {
628
        $this->customer = $customer;
629 3
        return $this;
630 3
    }
631
632
    /**
633
     * @return DeliveryInterface|null
634
     */
635
    public function getDelivery()
636 12
    {
637
        return $this->delivery;
638 12
    }
639
640
    /**
641
     * @param DeliveryInterface|null $delivery
642
     * @return OrderInterface
643
     */
644
    public function setDelivery($delivery)
645 3
    {
646
        $this->delivery = $delivery;
647 3
        return $this;
648 3
    }
649
650
    /**
651
     * @return InvoiceInterface|null
652
     */
653
    public function getInvoice()
654 3
    {
655
        return $this->invoice;
656 3
    }
657
658
    /**
659
     * @param InvoiceInterface|null $invoice
660
     * @return OrderInterface
661
     */
662
    public function setInvoice($invoice)
663 3
    {
664
        $this->invoice = $invoice;
665 3
        return $this;
666 3
    }
667
668
    /**
669
     * @return ArrayCollection|null
670
     */
671
    public function getOrderLines()
672 3
    {
673
        return $this->orderLines;
674 3
    }
675
676
    /**
677
     * @param ArrayCollection|null $orderLines
678
     * @return OrderInterface
679
     */
680
    public function setOrderLines($orderLines)
681 3
    {
682
        $this->orderLines = $orderLines;
683 3
        return $this;
684 3
    }
685
686
    /**
687
     * @return PaymentMethodInterface|null
688
     */
689
    public function getPaymentMethod()
690 3
    {
691
        return $this->paymentMethod;
692 3
    }
693
694
    /**
695
     * @param PaymentMethodInterface|null $paymentMethod
696
     * @return OrderInterface
697
     */
698
    public function setPaymentMethod($paymentMethod)
699 3
    {
700
        $this->paymentMethod = $paymentMethod;
701 3
        return $this;
702 3
    }
703
704
    /**
705
     * @return ShippingMethodInterface|null
706
     */
707
    public function getShippingMethod()
708 3
    {
709
        return $this->shippingMethod;
710 3
    }
711
712
    /**
713
     * @param ShippingMethodInterface|null $shippingMethod
714
     * @return OrderInterface
715
     */
716
    public function setShippingMethod($shippingMethod)
717 3
    {
718
        $this->shippingMethod = $shippingMethod;
719 3
        return $this;
720 3
    }
721
722
    /**
723
     * @return SiteInterface|null
724
     */
725
    public function getSite()
726 3
    {
727
        return $this->site;
728 3
    }
729
730
    /**
731
     * @param SiteInterface|null $site
732
     * @return OrderInterface
733
     */
734
    public function setSite($site)
735 3
    {
736
        $this->site = $site;
737 3
        return $this;
738 3
    }
739
740
    /**
741
     * @return StateInterface|null
742
     */
743
    public function getState()
744 3
    {
745
        return $this->state;
746 3
    }
747
748
    /**
749
     * @param StateInterface|null $state
750
     * @return OrderInterface
751
     */
752
    public function setState($state)
753 3
    {
754
        $this->state = $state;
755 3
        return $this;
756 3
    }
757
758
    /**
759
     * @return null|string
760
     */
761
    public function getComment()
762 3
    {
763
        return $this->comment;
764 3
    }
765
766
    /**
767
     * @param null|string $comment
768
     * @return OrderInterface
769
     */
770
    public function setComment($comment)
771 3
    {
772
        $this->comment = $comment;
773 3
        return $this;
774 3
    }
775
776
    /**
777
     * @return \DateTimeImmutable|null
778
     */
779
    public function getCreatedDate()
780 6
    {
781
        return $this->createdDate;
782 6
    }
783
784
    /**
785
     * @param \DateTimeImmutable|null $createdDate
786
     * @return OrderInterface
787
     */
788
    public function setCreatedDate($createdDate)
789 6
    {
790
        $this->createdDate = $createdDate;
791 6
        return $this;
792 6
    }
793
794
    /**
795
     * @return null|string
796
     */
797
    public function getCreditNoteNumber()
798 3
    {
799
        return $this->creditNoteNumber;
800 3
    }
801
802
    /**
803
     * @param null|string $creditNoteNumber
804
     * @return Order
805
     */
806
    public function setCreditNoteNumber($creditNoteNumber)
807 3
    {
808
        $this->creditNoteNumber = $creditNoteNumber;
809 3
        return $this;
810 3
    }
811
812
    /**
813
     * @return CurrencyInterface|null
814
     */
815
    public function getCurrency()
816 3
    {
817
        return $this->currency;
818 3
    }
819
820
    /**
821
     * @param null|CurrencyInterface $currency
822
     * @return OrderInterface
823
     */
824
    public function setCurrency($currency)
825 3
    {
826
        $this->currency = $currency;
827 3
        return $this;
828 3
    }
829
830
    /**
831
     * @return null|string
832
     */
833
    public function getCustomerComment()
834 3
    {
835
        return $this->customerComment;
836 3
    }
837
838
    /**
839
     * @param null|string $customerComment
840
     * @return OrderInterface
841
     */
842
    public function setCustomerComment($customerComment)
843 3
    {
844
        $this->customerComment = $customerComment;
845 3
        return $this;
846 3
    }
847
848
    /**
849
     * @return null|string
850
     */
851
    public function getGiftCertificateNumber()
852 3
    {
853
        return $this->giftCertificateNumber;
854 3
    }
855
856
    /**
857
     * @param null|string $giftCertificateNumber
858
     * @return OrderInterface
859
     */
860
    public function setGiftCertificateNumber($giftCertificateNumber)
861 3
    {
862
        $this->giftCertificateNumber = $giftCertificateNumber;
863 3
        return $this;
864 3
    }
865
866
    /**
867
     * @return bool|null
868
     */
869
    public function getIncomplete()
870 3
    {
871
        return $this->incomplete;
872 3
    }
873
874
    /**
875
     * @param bool|null $incomplete
876
     * @return OrderInterface
877
     */
878
    public function setIncomplete($incomplete)
879 3
    {
880
        $this->incomplete = $incomplete;
881 3
        return $this;
882 3
    }
883
884
    /**
885
     * @return null|string
886
     */
887
    public function getIp()
888 3
    {
889
        return $this->ip;
890 3
    }
891
892
    /**
893
     * @param null|string $ip
894
     * @return OrderInterface
895
     */
896
    public function setIp($ip)
897 3
    {
898
        $this->ip = $ip;
899 3
        return $this;
900 3
    }
901
902
    /**
903
     * @return bool|null
904
     */
905
    public function getModified()
906 3
    {
907
        return $this->modified;
908 3
    }
909
910
    /**
911
     * @param bool|null $modified
912
     * @return OrderInterface
913
     */
914
    public function setModified($modified)
915 3
    {
916
        $this->modified = $modified;
917 3
        return $this;
918 3
    }
919
920
    /**
921
     * @return \DateTimeImmutable|null
922
     */
923
    public function getModifiedDate()
924 3
    {
925
        return $this->modifiedDate;
926 3
    }
927
928
    /**
929
     * @param \DateTimeImmutable|null $modifiedDate
930
     * @return OrderInterface
931
     */
932
    public function setModifiedDate($modifiedDate)
933 3
    {
934
        $this->modifiedDate = $modifiedDate;
935 3
        return $this;
936 3
    }
937
938
    /**
939
     * @return null|string
940
     */
941
    public function getReferenceNumber()
942 3
    {
943
        return $this->referenceNumber;
944 3
    }
945
946
    /**
947
     * @param null|string $referenceNumber
948
     * @return OrderInterface
949
     */
950
    public function setReferenceNumber($referenceNumber)
951 3
    {
952
        $this->referenceNumber = $referenceNumber;
953 3
        return $this;
954 3
    }
955
956
    /**
957
     * @return null|string
958
     */
959
    public function getReferrer()
960 3
    {
961
        return $this->referrer;
962 3
    }
963
964
    /**
965
     * @param null|string $referrer
966
     * @return OrderInterface
967
     */
968
    public function setReferrer($referrer)
969 3
    {
970
        $this->referrer = $referrer;
971 3
        return $this;
972 3
    }
973
974
    /**
975
     * @return null|string
976
     */
977
    public function getReservedField1()
978 3
    {
979
        return $this->reservedField1;
980 3
    }
981
982
    /**
983
     * @param null|string $reservedField1
984
     * @return OrderInterface
985
     */
986
    public function setReservedField1($reservedField1)
987 3
    {
988
        $this->reservedField1 = $reservedField1;
989 3
        return $this;
990 3
    }
991
992
    /**
993
     * @return null|string
994
     */
995
    public function getReservedField2()
996 3
    {
997
        return $this->reservedField2;
998 3
    }
999
1000
    /**
1001
     * @param null|string $reservedField2
1002
     * @return OrderInterface
1003
     */
1004
    public function setReservedField2($reservedField2)
1005 3
    {
1006
        $this->reservedField2 = $reservedField2;
1007 3
        return $this;
1008 3
    }
1009
1010
    /**
1011
     * @return null|string
1012
     */
1013
    public function getReservedField3()
1014 3
    {
1015
        return $this->reservedField3;
1016 3
    }
1017
1018
    /**
1019
     * @param null|string $reservedField3
1020
     * @return OrderInterface
1021
     */
1022
    public function setReservedField3($reservedField3)
1023 3
    {
1024
        $this->reservedField3 = $reservedField3;
1025 3
        return $this;
1026 3
    }
1027
1028
    /**
1029
     * @return null|string
1030
     */
1031
    public function getReservedField4()
1032 3
    {
1033
        return $this->reservedField4;
1034 3
    }
1035
1036
    /**
1037
     * @param null|string $reservedField4
1038
     * @return OrderInterface
1039
     */
1040
    public function setReservedField4($reservedField4)
1041 3
    {
1042
        $this->reservedField4 = $reservedField4;
1043 3
        return $this;
1044 3
    }
1045
1046
    /**
1047
     * @return null|string
1048
     */
1049
    public function getReservedField5()
1050 3
    {
1051
        return $this->reservedField5;
1052 3
    }
1053
1054
    /**
1055
     * @param null|string $reservedField5
1056
     * @return OrderInterface
1057
     */
1058
    public function setReservedField5($reservedField5)
1059 3
    {
1060
        $this->reservedField5 = $reservedField5;
1061 3
        return $this;
1062 3
    }
1063
1064
    /**
1065
     * @return float|null
1066
     */
1067
    public function getTotalWeight()
1068 3
    {
1069
        return $this->totalWeight;
1070 3
    }
1071
1072
    /**
1073
     * @param float|null $totalWeight
1074
     * @return OrderInterface
1075
     */
1076
    public function setTotalWeight($totalWeight)
1077 3
    {
1078
        $this->totalWeight = $totalWeight;
1079 3
        return $this;
1080 3
    }
1081
1082
    /**
1083
     * @return null|string
1084
     */
1085
    public function getTrackingNumber()
1086 3
    {
1087
        return $this->trackingNumber;
1088 3
    }
1089
1090
    /**
1091
     * @param null|string $trackingNumber
1092
     * @return OrderInterface
1093
     */
1094
    public function setTrackingNumber($trackingNumber)
1095 3
    {
1096
        $this->trackingNumber = $trackingNumber;
1097 3
        return $this;
1098 3
    }
1099
1100
    /**
1101
     * @return int|null
1102
     */
1103
    public function getTransactionNumber()
1104 3
    {
1105
        return $this->transactionNumber;
1106 3
    }
1107
1108
    /**
1109
     * @param int|null $transactionNumber
1110
     * @return OrderInterface
1111
     */
1112
    public function setTransactionNumber($transactionNumber)
1113 3
    {
1114
        $this->transactionNumber = $transactionNumber;
1115 3
        return $this;
1116 3
    }
1117
1118
    /**
1119
     * @return float|null
1120
     */
1121
    public function getVatPct()
1122 3
    {
1123
        return $this->vatPct;
1124 3
    }
1125
1126
    /**
1127
     * @param float|null $vatPct
1128
     * @return OrderInterface
1129
     */
1130
    public function setVatPct($vatPct)
1131 3
    {
1132
        $this->vatPct = $vatPct;
1133 3
        return $this;
1134 3
    }
1135
1136
    /**
1137
     * @return null|string
1138
     */
1139
    public function getVatRegNumber()
1140
    {
1141
        return $this->vatRegNumber;
1142
    }
1143 3
1144
    /**
1145 3
     * @param null|string $vatRegNumber
1146
     * @return OrderInterface
1147
     */
1148
    public function setVatRegNumber($vatRegNumber)
1149
    {
1150
        $this->vatRegNumber = $vatRegNumber;
1151
        return $this;
1152
    }
1153
1154
    /**
1155
     * @return null|string
1156
     */
1157
    public function getXmlParams()
1158
    {
1159
        return $this->xmlParams;
1160
    }
1161
1162
    /**
1163
     * @param null|string $xmlParams
1164
     * @return OrderInterface
1165
     */
1166
    public function setXmlParams($xmlParams)
1167
    {
1168
        $this->xmlParams = $xmlParams;
1169
        return $this;
1170
    }
1171
1172
    protected function findOrderLine(OrderLineInterface $orderLine) : ?OrderLineInterface
1173
    {
1174
        foreach ($this->orderLines as $ol) {
1175
            if ($orderLine->getExternalId() === $ol->getExternalId()) {
1176
                return $ol;
1177
            }
1178
        }
1179
1180
        return null;
1181
    }
1182
1183
    /**
1184
     * A helper method for creating a Money object from a float based on the shared currency
1185
     *
1186
     * @param int $amount
1187
     * @return Money|null
1188
     */
1189
    private function createMoney(int $amount = 0) : ?Money
1190
    {
1191
        if (!$this->currency) {
1192
            return null;
1193
        }
1194
1195
        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

1195
        return /** @scrutinizer ignore-call */ DandomainFoundation\createMoney($this->currency->getIsoCodeAlpha(), $amount);
Loading history...
1196
    }
1197
}
1198