Completed
Push — master ( 842c53...e59924 )
by Joachim
14:33
created

Order   F

Complexity

Total Complexity 88

Size/Duplication

Total Lines 1123
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1123
rs 0.6314
c 0
b 0
f 0
wmc 88

80 Methods

Rating   Name   Duplication   Size   Complexity  
A setModifiedDate() 0 4 1
A getTransactionNumber() 0 3 1
A setInvoice() 0 4 1
A setModified() 0 4 1
A getShippingMethodFee() 0 3 1
A getPaymentMethod() 0 3 1
A __construct() 0 3 1
A setState() 0 4 1
A getVatPct() 0 3 1
A setPaymentMethod() 0 4 1
A getReservedField5() 0 3 1
A getIncomplete() 0 3 1
A setDelivery() 0 4 1
A createMoney() 0 3 1
A getReservedField4() 0 3 1
A setCustomer() 0 4 1
A getVatRegNumber() 0 3 1
A getIp() 0 3 1
A setIncomplete() 0 4 1
A getCustomerComment() 0 3 1
D populateFromApiResponse() 0 112 9
A getXmlParams() 0 3 1
A setSite() 0 4 1
A setIp() 0 4 1
A getCreatedDate() 0 3 1
A getState() 0 3 1
A setReservedField1() 0 4 1
A setTotalPrice() 0 5 1
A getReservedField1() 0 3 1
A setComment() 0 4 1
A setTransactionNumber() 0 4 1
A getGiftCertificateNumber() 0 3 1
A setShippingMethod() 0 4 1
A setSalesDiscount() 0 5 1
A getInvoice() 0 3 1
A setXmlParams() 0 4 1
A getReferenceNumber() 0 3 1
A setId() 0 4 1
A setTrackingNumber() 0 4 1
A getExternalId() 0 3 1
A setReservedField4() 0 4 1
A getDelivery() 0 3 1
A setTotalWeight() 0 4 1
A getCustomer() 0 3 1
A getSalesDiscount() 0 3 1
A setGiftCertificateNumber() 0 4 1
A getCreditNoteNumber() 0 3 1
A setReservedField5() 0 4 1
A getReservedField2() 0 3 1
A getTotalPrice() 0 3 1
A getSite() 0 3 1
A setOrderLines() 0 4 1
A setPaymentMethodFee() 0 5 1
A setShippingMethodFee() 0 5 1
A setVatRegNumber() 0 4 1
A getComment() 0 3 1
A setCreatedDate() 0 4 1
A getReferrer() 0 3 1
A getModifiedDate() 0 3 1
A getGiftCertificateAmount() 0 3 1
A setExternalId() 0 4 1
A getPaymentMethodFee() 0 3 1
A setGiftCertificateAmount() 0 5 1
A setCreditNoteNumber() 0 4 1
A setReferenceNumber() 0 4 1
A setReservedField3() 0 4 1
A getShippingMethod() 0 3 1
A getTotalWeight() 0 3 1
A getTrackingNumber() 0 3 1
A setReservedField2() 0 4 1
A setVatPct() 0 4 1
A createMoneyFromFloat() 0 3 1
A setReferrer() 0 4 1
A getOrderLines() 0 3 1
A getId() 0 3 1
A getCurrencyCode() 0 3 1
A getReservedField3() 0 3 1
A setCurrencyCode() 0 4 1
A getModified() 0 3 1
A setCustomerComment() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like Order often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Order, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Loevgaard\DandomainFoundation\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Loevgaard\DandomainDateTime\DateTimeImmutable;
8
use Loevgaard\DandomainFoundation;
9
use Loevgaard\DandomainFoundation\Entity\Generated\CustomerInterface;
10
use Loevgaard\DandomainFoundation\Entity\Generated\DeliveryInterface;
11
use Loevgaard\DandomainFoundation\Entity\Generated\InvoiceInterface;
12
use Loevgaard\DandomainFoundation\Entity\Generated\OrderInterface;
13
use Loevgaard\DandomainFoundation\Entity\Generated\OrderTraits;
14
use Loevgaard\DandomainFoundation\Entity\Generated\PaymentMethodInterface;
15
use Loevgaard\DandomainFoundation\Entity\Generated\ShippingMethodInterface;
16
use Loevgaard\DandomainFoundation\Entity\Generated\SiteInterface;
17
use Loevgaard\DandomainFoundation\Entity\Generated\StateInterface;
18
use Money\Currency;
19
use Money\Money;
20
21
/**
22
 * We use the Money library for amounts, and we use a shared currency, namely the property $currencyCode
23
 *
24
 * @ORM\Entity()
25
 * @ORM\Table(name="loevgaard_dandomain_orders")
26
 */
27
class Order implements OrderInterface
28
{
29
    use OrderTraits;
30
31
    /**
32
     * @var int
33
     *
34
     * @ORM\Id
35
     * @ORM\GeneratedValue
36
     * @ORM\Column(type="integer")
37
     **/
38
    protected $id;
39
40
    /**
41
     * This is the order id in Dandomain
42
     *
43
     * @var int
44
     *
45
     * @ORM\Column(type="integer", unique=true)
46
     */
47
    protected $externalId;
48
49
    /**
50
     * @var CustomerInterface|null
51
     *
52
     * @ORM\JoinColumn(onDelete="SET NULL")
53
     * @ORM\ManyToOne(targetEntity="Customer", cascade={"persist", "remove"})
54
     */
55
    protected $customer;
56
57
    /**
58
     * @var DeliveryInterface|null
59
     *
60
     * @ORM\JoinColumn(onDelete="SET NULL")
61
     * @ORM\ManyToOne(targetEntity="Delivery", cascade={"persist", "remove"})
62
     */
63
    protected $delivery;
64
65
    /**
66
     * @var InvoiceInterface|null
67
     *
68
     * @ORM\JoinColumn(onDelete="SET NULL")
69
     * @ORM\ManyToOne(targetEntity="Invoice", cascade={"persist", "remove"})
70
     */
71
    protected $invoice;
72
73
    /**
74
     * @var ArrayCollection|null
75
     *
76
     * @ORM\OneToMany(mappedBy="order", targetEntity="OrderLine", cascade={"persist", "remove"})
77
     */
78
    protected $orderLines;
79
80
    /**
81
     * @var PaymentMethodInterface|null
82
     *
83
     * @ORM\JoinColumn(onDelete="SET NULL")
84
     * @ORM\ManyToOne(targetEntity="PaymentMethod", cascade={"persist", "remove"})
85
     */
86
    protected $paymentMethod;
87
88
    /**
89
     * Because the fee can change on the payment method we have a field for here for the fee on this order
90
     *
91
     * @var integer|null
92
     *
93
     * @ORM\Column(type="integer", nullable=true)
94
     */
95
    protected $paymentMethodFee;
96
97
    /**
98
     * @var ShippingMethodInterface|null
99
     *
100
     * @ORM\JoinColumn(onDelete="SET NULL")
101
     * @ORM\ManyToOne(targetEntity="ShippingMethod", cascade={"persist", "remove"})
102
     */
103
    protected $shippingMethod;
104
105
    /**
106
     * Because the fee can change on the shipping method we have a field for here for the fee on this order
107
     *
108
     * @var integer|null
109
     *
110
     * @ORM\Column(type="integer", nullable=true)
111
     */
112
    protected $shippingMethodFee;
113
114
    /**
115
     * @var SiteInterface|null
116
     *
117
     * @ORM\JoinColumn(onDelete="SET NULL")
118
     * @ORM\ManyToOne(targetEntity="Site", cascade={"persist", "remove"})
119
     */
120
    protected $site;
121
122
    /**
123
     * @var StateInterface|null
124
     *
125
     * @ORM\JoinColumn(onDelete="SET NULL")
126
     * @ORM\ManyToOne(targetEntity="State", cascade={"persist", "remove"})
127
     */
128
    protected $state;
129
130
    /**
131
     * @var string|null
132
     *
133
     * @ORM\Column(nullable=true, type="text")
134
     */
135
    protected $comment;
136
137
    /**
138
     * @var \DateTimeImmutable|null
139
     *
140
     * @ORM\Column(nullable=true, type="datetime_immutable")
141
     */
142
    protected $createdDate;
143
144
    /**
145
     * @var string|null
146
     *
147
     * @ORM\Column(nullable=true, type="string", length=191)
148
     */
149
    protected $creditNoteNumber;
150
151
    /**
152
     * @var string|null
153
     *
154
     * @ORM\Column(type="string", length=3, nullable=true)
155
     */
156
    protected $currencyCode;
157
158
    /**
159
     * @var string|null
160
     *
161
     * @ORM\Column(nullable=true, type="text")
162
     */
163
    protected $customerComment;
164
165
    /**
166
     * @var integer|null
167
     *
168
     * @ORM\Column(type="integer", nullable=true)
169
     */
170
    protected $giftCertificateAmount;
171
172
    /**
173
     * @var string|null
174
     *
175
     * @ORM\Column(nullable=true, type="string", length=191)
176
     */
177
    protected $giftCertificateNumber;
178
179
    /**
180
     * @var bool|null
181
     *
182
     * @ORM\Column(type="boolean", nullable=true)
183
     */
184
    protected $incomplete;
185
186
    /**
187
     * @var string|null
188
     *
189
     * @ORM\Column(nullable=true, type="string", length=191)
190
     */
191
    protected $ip;
192
193
    /**
194
     * @var bool|null
195
     *
196
     * @ORM\Column(type="boolean", nullable=true)
197
     */
198
    protected $modified;
199
200
    /**
201
     * @var \DateTimeImmutable|null
202
     *
203
     * @ORM\Column(nullable=true, type="datetime_immutable")
204
     */
205
    protected $modifiedDate;
206
207
    /**
208
     * @var string|null
209
     *
210
     * @ORM\Column(nullable=true, type="string", length=191)
211
     */
212
    protected $referenceNumber;
213
214
    /**
215
     * @var string|null
216
     *
217
     * @ORM\Column(nullable=true, type="string", length=191)
218
     */
219
    protected $referrer;
220
221
    /**
222
     * @var string|null
223
     *
224
     * @ORM\Column(nullable=true, type="string", length=191)
225
     */
226
    protected $reservedField1;
227
228
    /**
229
     * @var string|null
230
     *
231
     * @ORM\Column(nullable=true, type="string", length=191)
232
     */
233
    protected $reservedField2;
234
235
    /**
236
     * @var string|null
237
     *
238
     * @ORM\Column(nullable=true, type="string", length=191)
239
     */
240
    protected $reservedField3;
241
242
    /**
243
     * @var string|null
244
     *
245
     * @ORM\Column(nullable=true, type="string", length=191)
246
     */
247
    protected $reservedField4;
248
249
    /**
250
     * @var string|null
251
     *
252
     * @ORM\Column(nullable=true, type="string", length=191)
253
     */
254
    protected $reservedField5;
255
256
    /**
257
     * @var int|null
258
     *
259
     * @ORM\Column(type="integer", nullable=true)
260
     */
261
    protected $salesDiscount;
262
263
    /**
264
     * @var int|null
265
     *
266
     * @ORM\Column(type="integer", nullable=true)
267
     */
268
    protected $totalPrice;
269
270
    /**
271
     * @var float|null
272
     *
273
     * @ORM\Column(nullable=true, type="decimal", precision=12, scale=2)
274
     */
275
    protected $totalWeight;
276
277
    /**
278
     * @var string|null
279
     *
280
     * @ORM\Column(nullable=true, type="string", length=191)
281
     */
282
    protected $trackingNumber;
283
284
    /**
285
     * @var int|null
286
     *
287
     * @ORM\Column(nullable=true, type="string", length=191)
288
     */
289
    protected $transactionNumber;
290
291
    /**
292
     * @var float|null
293
     *
294
     * @ORM\Column(nullable=true, type="decimal", precision=5, scale=2)
295
     */
296
    protected $vatPct;
297
298
    /**
299
     * @var string|null
300
     *
301
     * @ORM\Column(nullable=true, type="string", length=191)
302
     */
303
    protected $vatRegNumber;
304
305
    /**
306
     * @var string|null
307
     *
308
     * @ORM\Column(nullable=true, type="text")
309
     */
310
    protected $xmlParams;
311
312
    public function __construct()
313
    {
314
        $this->orderLines = new ArrayCollection();
315
    }
316
317
    /**
318
     * Populates an order based on the response from the Dandomain API
319
     *
320
     * See the properties here:
321
     * http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/OrderService/help/operations/GetOrder
322
     *
323
     * @param \stdClass|array $data
324
     * @param bool $populateEmbedded
325
     * @return OrderInterface
326
     */
327
    public function populateFromApiResponse($data, $populateEmbedded) : OrderInterface
328
    {
329
        $data = DandomainFoundation\objectToArray($data);
330
331
        // set currency because we use the currency to create Money objects
332
        $this->setCurrencyCode($data['currencyCode']);
333
334
        // set shortcuts for embedded objects
335
        $orderLinesData = $data['orderLines'] ?? [];
0 ignored issues
show
Unused Code introduced by
The assignment to $orderLinesData is dead and can be removed.
Loading history...
336
        $paymentData = $data['paymentInfo'] ?? [];
337
        $shippingData = $data['shippingInfo'] ?? [];
338
339
        $createdDate = DateTimeImmutable::createFromJson($data['createdDate']);
340
        $modifiedDate = DateTimeImmutable::createFromJson($data['modifiedDate']);
341
342
        $giftCertificateAmount = $this->createMoneyFromFloat($data['giftCertificateAmount']);
343
        $totalPrice = $this->createMoneyFromFloat($data['totalPrice']);
344
        $salesDiscount = $this->createMoneyFromFloat($data['salesDiscount']);
345
        $paymentMethodFee = $this->createMoneyFromFloat($paymentData['fee'] ?? 0.0);
346
        $shippingMethodFee = $this->createMoneyFromFloat($shippingData['fee'] ?? 0.0);
347
348
        $this
349
            ->setExternalId($data['id'])
0 ignored issues
show
Bug introduced by
It seems like $data['id'] can also be of type string; however, parameter $externalId of Loevgaard\DandomainFound...\Order::setExternalId() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

349
            ->setExternalId(/** @scrutinizer ignore-type */ $data['id'])
Loading history...
350
            ->setComment($data['comment'])
351
            ->setCreatedDate($createdDate)
352
            ->setCustomerComment($data['customerComment'])
353
            ->setGiftCertificateAmount($giftCertificateAmount)
354
            ->setGiftCertificateNumber($data['giftCertificateNumber'])
355
            ->setIncomplete($data['incomplete'])
0 ignored issues
show
Bug introduced by
It seems like $data['incomplete'] can also be of type string; however, parameter $incomplete of Loevgaard\DandomainFound...\Order::setIncomplete() does only seem to accept null|boolean, maybe add an additional type check? ( Ignorable by Annotation )

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

355
            ->setIncomplete(/** @scrutinizer ignore-type */ $data['incomplete'])
Loading history...
356
            ->setIp($data['ip'])
357
            ->setModified($data['modified'])
0 ignored issues
show
Bug introduced by
It seems like $data['modified'] can also be of type string; however, parameter $modified of Loevgaard\DandomainFound...ty\Order::setModified() does only seem to accept null|boolean, maybe add an additional type check? ( Ignorable by Annotation )

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

357
            ->setModified(/** @scrutinizer ignore-type */ $data['modified'])
Loading history...
358
            ->setModifiedDate($modifiedDate)
359
            ->setReferenceNumber($data['referenceNumber'])
360
            ->setReferrer($data['referrer'])
361
            ->setReservedField1($data['reservedField1'])
362
            ->setReservedField2($data['reservedField2'])
363
            ->setReservedField3($data['reservedField3'])
364
            ->setReservedField4($data['reservedField4'])
365
            ->setReservedField5($data['reservedField5'])
366
            ->setSalesDiscount($salesDiscount)
367
            ->setTotalPrice($totalPrice)
368
            ->setTotalWeight($data['totalWeight'])
0 ignored issues
show
Bug introduced by
It seems like $data['totalWeight'] can also be of type string; however, parameter $totalWeight of Loevgaard\DandomainFound...Order::setTotalWeight() does only seem to accept null|double, maybe add an additional type check? ( Ignorable by Annotation )

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

368
            ->setTotalWeight(/** @scrutinizer ignore-type */ $data['totalWeight'])
Loading history...
369
            ->setTrackingNumber($data['trackingNumber'])
370
            ->setTransactionNumber($data['transactionNumber'])
0 ignored issues
show
Bug introduced by
It seems like $data['transactionNumber'] can also be of type string; however, parameter $transactionNumber of Loevgaard\DandomainFound...:setTransactionNumber() does only seem to accept null|integer, maybe add an additional type check? ( Ignorable by Annotation )

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

370
            ->setTransactionNumber(/** @scrutinizer ignore-type */ $data['transactionNumber'])
Loading history...
371
            ->setVatPct($data['vatPct'])
0 ignored issues
show
Bug introduced by
It seems like $data['vatPct'] can also be of type string; however, parameter $vatPct of Loevgaard\DandomainFound...tity\Order::setVatPct() does only seem to accept null|double, maybe add an additional type check? ( Ignorable by Annotation )

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

371
            ->setVatPct(/** @scrutinizer ignore-type */ $data['vatPct'])
Loading history...
372
            ->setVatRegNumber($data['vatRegNumber'])
373
            ->setXmlParams($data['xmlParams'])
374
            ->setShippingMethodFee($shippingMethodFee)
375
            ->setPaymentMethodFee($paymentMethodFee)
376
        ;
377
378
        if ($populateEmbedded) {
379
            // populate customer
380
            $customer = $this->getCustomer();
381
            if (!$customer) {
382
                $customer = new Customer();
383
                $this->setCustomer($customer);
384
            }
385
            $customer->populateFromApiResponse($data['customerInfo']);
0 ignored issues
show
Bug introduced by
It seems like $data['customerInfo'] can also be of type string; however, parameter $data of Loevgaard\DandomainFound...pulateFromApiResponse() does only seem to accept stdClass|array, maybe add an additional type check? ( Ignorable by Annotation )

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

385
            $customer->populateFromApiResponse(/** @scrutinizer ignore-type */ $data['customerInfo']);
Loading history...
Bug introduced by
It seems like $data['customerInfo'] can also be of type string; however, parameter $data of Loevgaard\DandomainFound...pulateFromApiResponse() does only seem to accept stdClass|array, maybe add an additional type check? ( Ignorable by Annotation )

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

385
            $customer->populateFromApiResponse(/** @scrutinizer ignore-type */ $data['customerInfo']);
Loading history...
386
387
            // populate delivery info
388
            $delivery = $this->getDelivery();
389
            if (!$delivery) {
390
                $delivery = new Delivery();
391
                $this->setDelivery($delivery);
392
            }
393
            $delivery->populateFromApiResponse($data['deliveryInfo']);
0 ignored issues
show
Bug introduced by
It seems like $data['deliveryInfo'] can also be of type string; however, parameter $data of Loevgaard\DandomainFound...pulateFromApiResponse() does only seem to accept stdClass|array, maybe add an additional type check? ( Ignorable by Annotation )

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

393
            $delivery->populateFromApiResponse(/** @scrutinizer ignore-type */ $data['deliveryInfo']);
Loading history...
Bug introduced by
It seems like $data['deliveryInfo'] can also be of type string; however, parameter $data of Loevgaard\DandomainFound...pulateFromApiResponse() does only seem to accept stdClass|array, maybe add an additional type check? ( Ignorable by Annotation )

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

393
            $delivery->populateFromApiResponse(/** @scrutinizer ignore-type */ $data['deliveryInfo']);
Loading history...
394
395
            // populate invoice info
396
            $invoice = $this->getInvoice();
397
            if (!$invoice) {
398
                $invoice = new Invoice();
399
                $this->setInvoice($invoice);
400
            }
401
            $invoice->populateFromApiResponse($data['invoiceInfo']);
0 ignored issues
show
Bug introduced by
It seems like $data['invoiceInfo'] can also be of type string; however, parameter $data of Loevgaard\DandomainFound...pulateFromApiResponse() does only seem to accept stdClass|array, maybe add an additional type check? ( Ignorable by Annotation )

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

401
            $invoice->populateFromApiResponse(/** @scrutinizer ignore-type */ $data['invoiceInfo']);
Loading history...
Bug introduced by
It seems like $data['invoiceInfo'] can also be of type string; however, parameter $data of Loevgaard\DandomainFound...pulateFromApiResponse() does only seem to accept stdClass|array, maybe add an additional type check? ( Ignorable by Annotation )

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

401
            $invoice->populateFromApiResponse(/** @scrutinizer ignore-type */ $data['invoiceInfo']);
Loading history...
402
403
            // populate payment info
404
            $paymentMethod = $this->getPaymentMethod();
405
            if (!$paymentMethod) {
406
                $paymentMethod = new PaymentMethod();
407
                $paymentMethod->populateFromApiResponse($data['paymentInfo'], (string)$data['currencyCode']);
0 ignored issues
show
Bug introduced by
It seems like $data['paymentInfo'] can also be of type string; however, parameter $data of Loevgaard\DandomainFound...pulateFromApiResponse() does only seem to accept stdClass|array, maybe add an additional type check? ( Ignorable by Annotation )

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

407
                $paymentMethod->populateFromApiResponse(/** @scrutinizer ignore-type */ $data['paymentInfo'], (string)$data['currencyCode']);
Loading history...
408
            }
409
            $this->setPaymentMethod($paymentMethod);
410
411
            // populate shipping info
412
            $shippingMethod = $this->getShippingMethod();
413
            if (!$shippingMethod) {
414
                $shippingMethod = new ShippingMethod();
415
                $shippingMethod->populateFromApiResponse($data['shippingInfo'], (string)$data['currencyCode']);
0 ignored issues
show
Bug introduced by
It seems like $data['shippingInfo'] can also be of type string; however, parameter $data of Loevgaard\DandomainFound...pulateFromApiResponse() does only seem to accept stdClass|array, maybe add an additional type check? ( Ignorable by Annotation )

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

415
                $shippingMethod->populateFromApiResponse(/** @scrutinizer ignore-type */ $data['shippingInfo'], (string)$data['currencyCode']);
Loading history...
416
            }
417
            $this->setShippingMethod($shippingMethod);
418
419
            // populate site
420
            $site = $this->getSite();
421
            if (!$site) {
422
                $site = new Site();
423
                $site->setExternalId($data['siteId']);
0 ignored issues
show
Bug introduced by
It seems like $data['siteId'] can also be of type string; however, parameter $externalId of Loevgaard\DandomainFound...y\Site::setExternalId() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

423
                $site->setExternalId(/** @scrutinizer ignore-type */ $data['siteId']);
Loading history...
424
            }
425
            $this->setSite($site);
426
427
            // populate state
428
            $state = $this->getState();
429
            if (!$state) {
430
                $state = new State();
431
                $state->populateFromApiResponse($data['orderState']);
0 ignored issues
show
Bug introduced by
It seems like $data['orderState'] can also be of type string; however, parameter $data of Loevgaard\DandomainFound...pulateFromApiResponse() does only seem to accept stdClass|array, maybe add an additional type check? ( Ignorable by Annotation )

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

431
                $state->populateFromApiResponse(/** @scrutinizer ignore-type */ $data['orderState']);
Loading history...
432
            }
433
            $this->setState($state);
434
435
            // @todo create order lines
436
        }
437
438
        return $this;
439
    }
440
441
    /**
442
     * @return Money|null
443
     */
444
    public function getTotalPrice() : ?Money
445
    {
446
        return $this->createMoney((int)$this->totalPrice);
447
    }
448
449
    /**
450
     * @param Money $money
451
     * @return OrderInterface
452
     */
453
    public function setTotalPrice(Money $money = null) : OrderInterface
454
    {
455
        $this->totalPrice = $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 $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...
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

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