Completed
Push — master ( 70e9d1...4dda3a )
by Joachim
04:44
created

Payment::setCustomerCountryCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Loevgaard\Dandomain\Pay\Model;
4
5
use Money\Currency;
6
use Money\Money;
7
use Psr\Http\Message\ServerRequestInterface;
8
9
class Payment
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $apiKey;
15
16
    /**
17
     * @var string
18
     */
19
    protected $merchant;
20
21
    /**
22
     * @var int
23
     */
24
    protected $orderId;
25
26
    /**
27
     * @var string
28
     */
29
    protected $sessionId;
30
31
    /**
32
     * @var string
33
     */
34
    protected $currencySymbol;
35
36
    /**
37
     * @var Money
38
     */
39
    protected $totalAmount;
40
41
    /**
42
     * @var string
43
     */
44
    protected $callBackUrl;
45
46
    /**
47
     * @var string
48
     */
49
    protected $fullCallBackOkUrl;
50
51
    /**
52
     * @var string
53
     */
54
    protected $callBackOkUrl;
55
56
    /**
57
     * @var string
58
     */
59
    protected $callBackServerUrl;
60
61
    /**
62
     * @var int
63
     */
64
    protected $languageId;
65
66
    /**
67
     * @var bool
68
     */
69
    protected $testMode;
70
71
    /**
72
     * @var int
73
     */
74
    protected $paymentGatewayCurrencyCode;
75
76
    /**
77
     * @var int
78
     */
79
    protected $cardTypeId;
80
81
    /**
82
     * @var string
83
     */
84
    protected $customerRekvNr;
85
86
    /**
87
     * @var string
88
     */
89
    protected $customerName;
90
91
    /**
92
     * @var string
93
     */
94
    protected $customerCompany;
95
96
    /**
97
     * @var string
98
     */
99
    protected $customerAddress;
100
101
    /**
102
     * @var string
103
     */
104
    protected $customerAddress2;
105
106
    /**
107
     * @var string
108
     */
109
    protected $customerZipCode;
110
111
    /**
112
     * @var string
113
     */
114
    protected $customerCity;
115
116
    /**
117
     * @var int
118
     */
119
    protected $customerCountryId;
120
121
    /**
122
     * @var string
123
     */
124
    protected $customerCountry;
125
126
    /**
127
     * This is the ISO 639-2 country code
128
     *
129
     * @var string
130
     */
131
    protected $customerCountryCode;
132
133
    /**
134
     * @var string
135
     */
136
    protected $customerPhone;
137
138
    /**
139
     * @var string
140
     */
141
    protected $customerFax;
142
143
    /**
144
     * @var string
145
     */
146
    protected $customerEmail;
147
148
    /**
149
     * @var string
150
     */
151
    protected $customerNote;
152
153
    /**
154
     * @var string
155
     */
156
    protected $customerCvrnr;
157
158
    /**
159
     * @var int
160
     */
161
    protected $customerCustTypeId;
162
163
    /**
164
     * @var string
165
     */
166
    protected $customerEan;
167
168
    /**
169
     * @var string
170
     */
171
    protected $customerRes1;
172
173
    /**
174
     * @var string
175
     */
176
    protected $customerRes2;
177
178
    /**
179
     * @var string
180
     */
181
    protected $customerRes3;
182
183
    /**
184
     * @var string
185
     */
186
    protected $customerRes4;
187
188
    /**
189
     * @var string
190
     */
191
    protected $customerRes5;
192
193
    /**
194
     * @var string
195
     */
196
    protected $customerIp;
197
198
    /**
199
     * @var string
200
     */
201
    protected $deliveryName;
202
203
    /**
204
     * @var string
205
     */
206
    protected $deliveryCompany;
207
208
    /**
209
     * @var string
210
     */
211
    protected $deliveryAddress;
212
213
    /**
214
     * @var string
215
     */
216
    protected $deliveryAddress2;
217
218
    /**
219
     * @var string
220
     */
221
    protected $deliveryZipCode;
222
223
    /**
224
     * @var string
225
     */
226
    protected $deliveryCity;
227
228
    /**
229
     * @var int
230
     */
231
    protected $deliveryCountryID;
232
233
    /**
234
     * @var string
235
     */
236
    protected $deliveryCountry;
237
238
    /**
239
     * @var string
240
     */
241
    protected $deliveryPhone;
242
243
    /**
244
     * @var string
245
     */
246
    protected $deliveryFax;
247
248
    /**
249
     * @var string
250
     */
251
    protected $deliveryEmail;
252
253
    /**
254
     * @var string
255
     */
256
    protected $deliveryEan;
257
258
    /**
259
     * @var string
260
     */
261
    protected $shippingMethod;
262
263
    /**
264
     * @var int
265
     */
266
    protected $shippingMethodId;
267
268
    /**
269
     * @var Money
270
     */
271
    protected $shippingFee;
272
273
    /**
274
     * @var string
275
     */
276
    protected $paymentMethod;
277
278
    /**
279
     * @var int
280
     */
281
    protected $paymentMethodId;
282
283
    /**
284
     * @var Money
285
     */
286
    protected $paymentFee;
287
288
    /**
289
     * @var string
290
     */
291
    protected $loadBalancerRealIp;
292
293
    /**
294
     * @var string
295
     */
296
    protected $referrer;
297
298
    /**
299
     * @var PaymentLine[]
300
     */
301
    protected $paymentLines;
302
303 18
    public function __construct()
304
    {
305 18
        $this->paymentLines = [];
306 18
    }
307
    
308 6
    public static function createFromRequest(ServerRequestInterface $request) : Payment
309
    {
310 6
        $payment = new static();
311 6
        $payment->populateFromRequest($request);
312 6
        return $payment;
313
    }
314
315 6
    public function populateFromRequest(ServerRequestInterface $request)
316
    {
317 6
        $body = $request->getParsedBody();
318 6
        $body = is_array($body) ? $body : [];
319
320
        // set currency because we use it to create Money objects
321 6
        $this->setCurrencySymbol($body['APICurrencySymbol'] ?? '');
322
        
323 6
        $totalAmount = $this->createMoneyFromFloat($body['APITotalAmount'] ?? '0.00');
324 6
        if ($totalAmount) {
325 3
            $this->setTotalAmount($totalAmount);
326
        }
327
328 6
        $shippingFee = $this->createMoneyFromFloat($body['APIShippingFee'] ?? '0.00');
329 6
        if ($shippingFee) {
330 3
            $this->setShippingFee($shippingFee);
331
        }
332
333 6
        $paymentFee = $this->createMoneyFromFloat($body['APIPayFee'] ?? '0.00');
334 6
        if ($paymentFee) {
335 3
            $this->setPaymentFee($paymentFee);
336
        }
337
338 6
        $this->setApiKey($body['APIkey'] ?? '');
339 6
        $this->setMerchant($body['APIMerchant'] ?? '');
340 6
        $this->setOrderId($body['APIOrderID'] ?? 0);
341 6
        $this->setSessionId($body['APISessionID'] ?? '');
342 6
        $this->setCallBackUrl($body['APICallBackUrl'] ?? '');
343 6
        $this->setFullCallBackOkUrl($body['APIFullCallBackOKUrl'] ?? '');
344 6
        $this->setCallBackOkUrl($body['APICallBackOKUrl'] ?? '');
345 6
        $this->setCallBackServerUrl($body['APICallBackServerUrl'] ?? '');
346 6
        $this->setLanguageId((int)($body['APILanguageID'] ?? 0));
347 6
        $this->setTestMode(isset($body['APITestMode']) && 'True' === $body['APITestMode']);
348 6
        $this->setPaymentGatewayCurrencyCode((int)($body['APIPayGatewayCurrCode'] ??  0));
349 6
        $this->setCardTypeId((int)($body['APICardTypeID'] ?? 0));
350 6
        $this->setCustomerRekvNr($body['APICRekvNr'] ?? '');
351 6
        $this->setCustomerName($body['APICName'] ?? '');
352 6
        $this->setCustomerCompany($body['APICCompany'] ?? '');
353 6
        $this->setCustomerAddress($body['APICAddress'] ?? '');
354 6
        $this->setCustomerAddress2($body['APICAddress2'] ?? '');
355 6
        $this->setCustomerZipCode($body['APICZipCode'] ?? '');
356 6
        $this->setCustomerCity($body['APICCity'] ?? '');
357 6
        $this->setCustomerCountryId((int)($body['APICCountryID'] ?? 0));
358 6
        $this->setCustomerCountry($body['APICCountry'] ?? '');
359 6
        $this->setCustomerCountryCode($body['APICCountryCode'] ?? '');
360 6
        $this->setCustomerPhone($body['APICPhone'] ?? '');
361 6
        $this->setCustomerFax($body['APICFax'] ?? '');
362 6
        $this->setCustomerEmail($body['APICEmail'] ?? '');
363 6
        $this->setCustomerNote($body['APICNote'] ?? '');
364 6
        $this->setCustomerCvrnr($body['APICcvrnr'] ?? '');
365 6
        $this->setCustomerCustTypeId((int)($body['APICCustTypeID'] ?? 0));
366 6
        $this->setCustomerEan($body['APICEAN'] ?? '');
367 6
        $this->setCustomerRes1($body['APICres1'] ?? '');
368 6
        $this->setCustomerRes2($body['APICres2'] ?? '');
369 6
        $this->setCustomerRes3($body['APICres3'] ?? '');
370 6
        $this->setCustomerRes4($body['APICres4'] ?? '');
371 6
        $this->setCustomerRes5($body['APICres5'] ?? '');
372 6
        $this->setDeliveryName($body['APIDName'] ?? '');
373 6
        $this->setDeliveryCompany($body['APIDCompany'] ?? '');
374 6
        $this->setDeliveryAddress($body['APIDAddress'] ?? '');
375 6
        $this->setDeliveryAddress2($body['APIDAddress2'] ?? '');
376 6
        $this->setDeliveryZipCode($body['APIDZipCode'] ?? '');
377 6
        $this->setDeliveryCity($body['APIDCity'] ?? '');
378 6
        $this->setDeliveryCountryID((int)($body['APIDCountryID'] ?? 0));
379 6
        $this->setDeliveryCountry($body['APIDCountry'] ?? '');
380 6
        $this->setDeliveryPhone($body['APIDPhone'] ?? '');
381 6
        $this->setDeliveryFax($body['APIDFax'] ?? '');
382 6
        $this->setDeliveryEmail($body['APIDEmail'] ?? '');
383 6
        $this->setDeliveryEan($body['APIDean'] ?? '');
384 6
        $this->setShippingMethod($body['APIShippingMethod'] ?? '');
385 6
        $this->setShippingMethodId((int)($body['APIShippingMethodID'] ?? 0));
386 6
        $this->setPaymentMethod($body['APIPayMethod'] ?? '');
387 6
        $this->setPaymentMethodId((int)($body['APIPayMethodID'] ?? 0));
388 6
        $this->setCustomerIp($body['APICIP'] ?? '');
389 6
        $this->setLoadBalancerRealIp($body['APILoadBalancerRealIP'] ?? '');
390 6
        $this->setReferrer($request->hasHeader('referer') ? $request->getHeaderLine('referer') : '');
391
392
        // populate order lines
393 6
        $i = 1;
394 6
        while (isset($body['APIBasketProdAmount'.$i])) {
395 3
            $qty = (int)$body['APIBasketProdAmount'.$i];
396 3
            $productNumber = $body['APIBasketProdNumber'.$i] ?? '';
397 3
            $name = $body['APIBasketProdName'.$i] ?? '';
398 3
            $price = $this->createMoneyFromFloat($body['APIBasketProdPrice'.$i] ?? '0.00');
399 3
            $vat = (int)($body['APIBasketProdVAT'.$i] ?? 0);
400
401 3
            $this->addPaymentLine(static::createPaymentLine($productNumber, $name, $qty, $price, $vat));
0 ignored issues
show
Bug introduced by
It seems like $price defined by $this->createMoneyFromFl...Price' . $i] ?? '0.00') on line 398 can be null; however, Loevgaard\Dandomain\Pay\...nt::createPaymentLine() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
402
403 3
            ++$i;
404
        }
405 6
    }
406
407 3
    public static function createPaymentLine(string $productNumber, string $name, int $quantity, Money $price, int $vat)
408
    {
409 3
        return new PaymentLine($productNumber, $name, $quantity, $price, $vat);
410
    }
411
412
    /**
413
     * Takes strings like
414
     * - 1.000,50
415
     * - 1,000.50
416
     * - 1000.50
417
     * - 1000,50.
418
     *
419
     * and returns 100050
420
     *
421
     * @param string $str
422
     * @param string $propertyPath
423
     *
424
     * @return int
425
     */
426 9
    public static function priceStringToInt(string $str, string $propertyPath = '') : int
427
    {
428 9
        $str = trim($str);
429
430
        // verify format of string
431 9
        if (!preg_match('/(\.|,)[0-9]{2}$/', $str)) {
432 3
            throw new \InvalidArgumentException(($propertyPath ? $propertyPath.' (value: "'.$str.'")' : $str).
433 3
                ' does not match the currency string format');
434
        }
435 9
        $str = preg_replace('/[^0-9]+/', '', $str);
436
437 9
        return intval($str);
438
    }
439
440
    /**
441
     * @return string
442
     */
443 6
    public function getApiKey(): ?string
444
    {
445 6
        return $this->apiKey;
446
    }
447
448
    /**
449
     * @param string $apiKey
450
     *
451
     * @return Payment
452
     */
453 9
    public function setApiKey(string $apiKey): self
454
    {
455 9
        $this->apiKey = $apiKey;
456
457 9
        return $this;
458
    }
459
460
    /**
461
     * @return string
462
     */
463 3
    public function getMerchant(): ?string
464
    {
465 3
        return $this->merchant;
466
    }
467
468
    /**
469
     * @param string $merchant
470
     *
471
     * @return Payment
472
     */
473 6
    public function setMerchant(string $merchant): self
474
    {
475 6
        $this->merchant = $merchant;
476
477 6
        return $this;
478
    }
479
480
    /**
481
     * @return int
482
     */
483 9
    public function getOrderId(): ?int
484
    {
485 9
        return $this->orderId;
486
    }
487
488
    /**
489
     * @param int $orderId
490
     *
491
     * @return Payment
492
     */
493 12
    public function setOrderId(int $orderId): self
494
    {
495 12
        $this->orderId = $orderId;
496
497 12
        return $this;
498
    }
499
500
    /**
501
     * @return string
502
     */
503 3
    public function getSessionId(): ?string
504
    {
505 3
        return $this->sessionId;
506
    }
507
508
    /**
509
     * @param string $sessionId
510
     *
511
     * @return Payment
512
     */
513 6
    public function setSessionId(string $sessionId): self
514
    {
515 6
        $this->sessionId = $sessionId;
516
517 6
        return $this;
518
    }
519
520
    /**
521
     * @return string
522
     */
523 3
    public function getCurrencySymbol(): ?string
524
    {
525 3
        return $this->currencySymbol;
526
    }
527
528
    /**
529
     * @param string $currencySymbol
530
     *
531
     * @return Payment
532
     */
533 6
    public function setCurrencySymbol(string $currencySymbol): self
534
    {
535 6
        $this->currencySymbol = $currencySymbol;
536
537 6
        return $this;
538
    }
539
540
    /**
541
     * @return Money
542
     */
543 9
    public function getTotalAmount(): ?Money
544
    {
545 9
        return $this->totalAmount;
546
    }
547
548
    /**
549
     * @param Money $totalAmount
550
     *
551
     * @return Payment
552
     */
553 6
    public function setTotalAmount(Money $totalAmount): self
554
    {
555 6
        $this->totalAmount = $totalAmount;
556
557 6
        return $this;
558
    }
559
560
    /**
561
     * @return string
562
     */
563 3
    public function getCallBackUrl(): ?string
564
    {
565 3
        return $this->callBackUrl;
566
    }
567
568
    /**
569
     * @param string $callBackUrl
570
     *
571
     * @return Payment
572
     */
573 6
    public function setCallBackUrl(string $callBackUrl): self
574
    {
575 6
        $this->callBackUrl = $callBackUrl;
576
577 6
        return $this;
578
    }
579
580
    /**
581
     * @return string
582
     */
583 3
    public function getFullCallBackOkUrl(): ?string
584
    {
585 3
        return $this->fullCallBackOkUrl;
586
    }
587
588
    /**
589
     * @param string $fullCallBackOkUrl
590
     *
591
     * @return Payment
592
     */
593 6
    public function setFullCallBackOkUrl(string $fullCallBackOkUrl): self
594
    {
595 6
        $this->fullCallBackOkUrl = $fullCallBackOkUrl;
596
597 6
        return $this;
598
    }
599
600
    /**
601
     * @return string
602
     */
603 3
    public function getCallBackOkUrl(): ?string
604
    {
605 3
        return $this->callBackOkUrl;
606
    }
607
608
    /**
609
     * @param string $callBackOkUrl
610
     *
611
     * @return Payment
612
     */
613 6
    public function setCallBackOkUrl(string $callBackOkUrl): self
614
    {
615 6
        $this->callBackOkUrl = $callBackOkUrl;
616
617 6
        return $this;
618
    }
619
620
    /**
621
     * @return string
622
     */
623 3
    public function getCallBackServerUrl(): ?string
624
    {
625 3
        return $this->callBackServerUrl;
626
    }
627
628
    /**
629
     * @param string $callBackServerUrl
630
     *
631
     * @return Payment
632
     */
633 6
    public function setCallBackServerUrl(string $callBackServerUrl): self
634
    {
635 6
        $this->callBackServerUrl = $callBackServerUrl;
636
637 6
        return $this;
638
    }
639
640
    /**
641
     * @return int
642
     */
643 3
    public function getLanguageId(): ?int
644
    {
645 3
        return $this->languageId;
646
    }
647
648
    /**
649
     * @param int $languageId
650
     *
651
     * @return Payment
652
     */
653 6
    public function setLanguageId(int $languageId): self
654
    {
655 6
        $this->languageId = $languageId;
656
657 6
        return $this;
658
    }
659
660
    /**
661
     * @return bool
662
     */
663 3
    public function isTestMode(): ?bool
664
    {
665 3
        return $this->testMode;
666
    }
667
668
    /**
669
     * @param bool $testMode
670
     *
671
     * @return Payment
672
     */
673 6
    public function setTestMode(bool $testMode): self
674
    {
675 6
        $this->testMode = $testMode;
676
677 6
        return $this;
678
    }
679
680
    /**
681
     * @return int
682
     */
683 9
    public function getPaymentGatewayCurrencyCode()
684
    {
685 9
        return $this->paymentGatewayCurrencyCode;
686
    }
687
688
    /**
689
     * @param int $paymentGatewayCurrencyCode
690
     *
691
     * @return Payment
692
     */
693 12
    public function setPaymentGatewayCurrencyCode(int $paymentGatewayCurrencyCode): self
694
    {
695 12
        $this->paymentGatewayCurrencyCode = $paymentGatewayCurrencyCode;
696
697 12
        return $this;
698
    }
699
700
    /**
701
     * @return int
702
     */
703 3
    public function getCardTypeId()
704
    {
705 3
        return $this->cardTypeId;
706
    }
707
708
    /**
709
     * @param int $cardTypeId
710
     *
711
     * @return Payment
712
     */
713 6
    public function setCardTypeId(int $cardTypeId): self
714
    {
715 6
        $this->cardTypeId = $cardTypeId;
716
717 6
        return $this;
718
    }
719
720
    /**
721
     * @return string
722
     */
723 3
    public function getCustomerRekvNr(): ?string
724
    {
725 3
        return $this->customerRekvNr;
726
    }
727
728
    /**
729
     * @param string $customerRekvNr
730
     *
731
     * @return Payment
732
     */
733 6
    public function setCustomerRekvNr(string $customerRekvNr): self
734
    {
735 6
        $this->customerRekvNr = $customerRekvNr;
736
737 6
        return $this;
738
    }
739
740
    /**
741
     * @return string
742
     */
743 3
    public function getCustomerName(): ?string
744
    {
745 3
        return $this->customerName;
746
    }
747
748
    /**
749
     * @param string $customerName
750
     *
751
     * @return Payment
752
     */
753 6
    public function setCustomerName(string $customerName): self
754
    {
755 6
        $this->customerName = $customerName;
756
757 6
        return $this;
758
    }
759
760
    /**
761
     * @return string
762
     */
763 3
    public function getCustomerCompany(): ?string
764
    {
765 3
        return $this->customerCompany;
766
    }
767
768
    /**
769
     * @param string $customerCompany
770
     *
771
     * @return Payment
772
     */
773 6
    public function setCustomerCompany(string $customerCompany): self
774
    {
775 6
        $this->customerCompany = $customerCompany;
776
777 6
        return $this;
778
    }
779
780
    /**
781
     * @return string
782
     */
783 3
    public function getCustomerAddress(): ?string
784
    {
785 3
        return $this->customerAddress;
786
    }
787
788
    /**
789
     * @param string $customerAddress
790
     *
791
     * @return Payment
792
     */
793 6
    public function setCustomerAddress(string $customerAddress): self
794
    {
795 6
        $this->customerAddress = $customerAddress;
796
797 6
        return $this;
798
    }
799
800
    /**
801
     * @return string
802
     */
803 3
    public function getCustomerAddress2(): ?string
804
    {
805 3
        return $this->customerAddress2;
806
    }
807
808
    /**
809
     * @param string $customerAddress2
810
     *
811
     * @return Payment
812
     */
813 6
    public function setCustomerAddress2(string $customerAddress2): self
814
    {
815 6
        $this->customerAddress2 = $customerAddress2;
816
817 6
        return $this;
818
    }
819
820
    /**
821
     * @return string
822
     */
823 3
    public function getCustomerZipCode(): ?string
824
    {
825 3
        return $this->customerZipCode;
826
    }
827
828
    /**
829
     * @param string $customerZipCode
830
     *
831
     * @return Payment
832
     */
833 6
    public function setCustomerZipCode(string $customerZipCode): self
834
    {
835 6
        $this->customerZipCode = $customerZipCode;
836
837 6
        return $this;
838
    }
839
840
    /**
841
     * @return string
842
     */
843 3
    public function getCustomerCity(): ?string
844
    {
845 3
        return $this->customerCity;
846
    }
847
848
    /**
849
     * @param string $customerCity
850
     *
851
     * @return Payment
852
     */
853 6
    public function setCustomerCity(string $customerCity): self
854
    {
855 6
        $this->customerCity = $customerCity;
856
857 6
        return $this;
858
    }
859
860
    /**
861
     * @return int
862
     */
863 3
    public function getCustomerCountryId()
864
    {
865 3
        return $this->customerCountryId;
866
    }
867
868
    /**
869
     * @param int $customerCountryId
870
     *
871
     * @return Payment
872
     */
873 6
    public function setCustomerCountryId(int $customerCountryId): self
874
    {
875 6
        $this->customerCountryId = $customerCountryId;
876
877 6
        return $this;
878
    }
879
880
    /**
881
     * @return string
882
     */
883 3
    public function getCustomerCountry(): ?string
884
    {
885 3
        return $this->customerCountry;
886
    }
887
888
    /**
889
     * @param string $customerCountry
890
     *
891
     * @return Payment
892
     */
893 6
    public function setCustomerCountry(string $customerCountry): self
894
    {
895 6
        $this->customerCountry = $customerCountry;
896
897 6
        return $this;
898
    }
899
900
    /**
901
     * @return string
902
     */
903 3
    public function getCustomerCountryCode(): ?string
904
    {
905 3
        return $this->customerCountryCode;
906
    }
907
908
    /**
909
     * @param string $customerCountryCode
910
     * @return Payment
911
     */
912 6
    public function setCustomerCountryCode(string $customerCountryCode): self
913
    {
914 6
        $this->customerCountryCode = $customerCountryCode;
915 6
        return $this;
916
    }
917
918
    /**
919
     * @return string
920
     */
921 3
    public function getCustomerPhone(): ?string
922
    {
923 3
        return $this->customerPhone;
924
    }
925
926
    /**
927
     * @param string $customerPhone
928
     *
929
     * @return Payment
930
     */
931 6
    public function setCustomerPhone(string $customerPhone): self
932
    {
933 6
        $this->customerPhone = $customerPhone;
934
935 6
        return $this;
936
    }
937
938
    /**
939
     * @return string
940
     */
941 3
    public function getCustomerFax(): ?string
942
    {
943 3
        return $this->customerFax;
944
    }
945
946
    /**
947
     * @param string $customerFax
948
     *
949
     * @return Payment
950
     */
951 6
    public function setCustomerFax(string $customerFax): self
952
    {
953 6
        $this->customerFax = $customerFax;
954
955 6
        return $this;
956
    }
957
958
    /**
959
     * @return string
960
     */
961 3
    public function getCustomerEmail(): ?string
962
    {
963 3
        return $this->customerEmail;
964
    }
965
966
    /**
967
     * @param string $customerEmail
968
     *
969
     * @return Payment
970
     */
971 6
    public function setCustomerEmail(string $customerEmail): self
972
    {
973 6
        $this->customerEmail = $customerEmail;
974
975 6
        return $this;
976
    }
977
978
    /**
979
     * @return string
980
     */
981 3
    public function getCustomerNote(): ?string
982
    {
983 3
        return $this->customerNote;
984
    }
985
986
    /**
987
     * @param string $customerNote
988
     *
989
     * @return Payment
990
     */
991 6
    public function setCustomerNote(string $customerNote): self
992
    {
993 6
        $this->customerNote = $customerNote;
994
995 6
        return $this;
996
    }
997
998
    /**
999
     * @return string
1000
     */
1001 3
    public function getCustomerCvrnr(): ?string
1002
    {
1003 3
        return $this->customerCvrnr;
1004
    }
1005
1006
    /**
1007
     * @param string $customerCvrnr
1008
     *
1009
     * @return Payment
1010
     */
1011 6
    public function setCustomerCvrnr(string $customerCvrnr): self
1012
    {
1013 6
        $this->customerCvrnr = $customerCvrnr;
1014
1015 6
        return $this;
1016
    }
1017
1018
    /**
1019
     * @return int
1020
     */
1021 3
    public function getCustomerCustTypeId(): ?int
1022
    {
1023 3
        return $this->customerCustTypeId;
1024
    }
1025
1026
    /**
1027
     * @param int $customerCustTypeId
1028
     *
1029
     * @return Payment
1030
     */
1031 6
    public function setCustomerCustTypeId(int $customerCustTypeId): self
1032
    {
1033 6
        $this->customerCustTypeId = $customerCustTypeId;
1034
1035 6
        return $this;
1036
    }
1037
1038
    /**
1039
     * @return string
1040
     */
1041 3
    public function getCustomerEan(): ?string
1042
    {
1043 3
        return $this->customerEan;
1044
    }
1045
1046
    /**
1047
     * @param string $customerEan
1048
     *
1049
     * @return Payment
1050
     */
1051 6
    public function setCustomerEan(string $customerEan): self
1052
    {
1053 6
        $this->customerEan = $customerEan;
1054
1055 6
        return $this;
1056
    }
1057
1058
    /**
1059
     * @return string
1060
     */
1061 3
    public function getCustomerRes1(): ?string
1062
    {
1063 3
        return $this->customerRes1;
1064
    }
1065
1066
    /**
1067
     * @param string $customerRes1
1068
     *
1069
     * @return Payment
1070
     */
1071 6
    public function setCustomerRes1(string $customerRes1): self
1072
    {
1073 6
        $this->customerRes1 = $customerRes1;
1074
1075 6
        return $this;
1076
    }
1077
1078
    /**
1079
     * @return string
1080
     */
1081 3
    public function getCustomerRes2(): ?string
1082
    {
1083 3
        return $this->customerRes2;
1084
    }
1085
1086
    /**
1087
     * @param string $customerRes2
1088
     *
1089
     * @return Payment
1090
     */
1091 6
    public function setCustomerRes2(string $customerRes2): self
1092
    {
1093 6
        $this->customerRes2 = $customerRes2;
1094
1095 6
        return $this;
1096
    }
1097
1098
    /**
1099
     * @return string
1100
     */
1101 3
    public function getCustomerRes3(): ?string
1102
    {
1103 3
        return $this->customerRes3;
1104
    }
1105
1106
    /**
1107
     * @param string $customerRes3
1108
     *
1109
     * @return Payment
1110
     */
1111 6
    public function setCustomerRes3(string $customerRes3): self
1112
    {
1113 6
        $this->customerRes3 = $customerRes3;
1114
1115 6
        return $this;
1116
    }
1117
1118
    /**
1119
     * @return string
1120
     */
1121 3
    public function getCustomerRes4(): ?string
1122
    {
1123 3
        return $this->customerRes4;
1124
    }
1125
1126
    /**
1127
     * @param string $customerRes4
1128
     *
1129
     * @return Payment
1130
     */
1131 6
    public function setCustomerRes4(string $customerRes4): self
1132
    {
1133 6
        $this->customerRes4 = $customerRes4;
1134
1135 6
        return $this;
1136
    }
1137
1138
    /**
1139
     * @return string
1140
     */
1141 3
    public function getCustomerRes5(): ?string
1142
    {
1143 3
        return $this->customerRes5;
1144
    }
1145
1146
    /**
1147
     * @param string $customerRes5
1148
     *
1149
     * @return Payment
1150
     */
1151 6
    public function setCustomerRes5(string $customerRes5): self
1152
    {
1153 6
        $this->customerRes5 = $customerRes5;
1154
1155 6
        return $this;
1156
    }
1157
1158
    /**
1159
     * @return string
1160
     */
1161 3
    public function getCustomerIp(): ?string
1162
    {
1163 3
        return $this->customerIp;
1164
    }
1165
1166
    /**
1167
     * @param string $customerIp
1168
     *
1169
     * @return Payment
1170
     */
1171 6
    public function setCustomerIp(string $customerIp): self
1172
    {
1173 6
        $this->customerIp = $customerIp;
1174
1175 6
        return $this;
1176
    }
1177
1178
    /**
1179
     * @return string
1180
     */
1181 3
    public function getDeliveryName(): ?string
1182
    {
1183 3
        return $this->deliveryName;
1184
    }
1185
1186
    /**
1187
     * @param string $deliveryName
1188
     *
1189
     * @return Payment
1190
     */
1191 6
    public function setDeliveryName(string $deliveryName): self
1192
    {
1193 6
        $this->deliveryName = $deliveryName;
1194
1195 6
        return $this;
1196
    }
1197
1198
    /**
1199
     * @return string
1200
     */
1201 3
    public function getDeliveryCompany(): ?string
1202
    {
1203 3
        return $this->deliveryCompany;
1204
    }
1205
1206
    /**
1207
     * @param string $deliveryCompany
1208
     *
1209
     * @return Payment
1210
     */
1211 6
    public function setDeliveryCompany(string $deliveryCompany): self
1212
    {
1213 6
        $this->deliveryCompany = $deliveryCompany;
1214
1215 6
        return $this;
1216
    }
1217
1218
    /**
1219
     * @return string
1220
     */
1221 3
    public function getDeliveryAddress(): ?string
1222
    {
1223 3
        return $this->deliveryAddress;
1224
    }
1225
1226
    /**
1227
     * @param string $deliveryAddress
1228
     *
1229
     * @return Payment
1230
     */
1231 6
    public function setDeliveryAddress(string $deliveryAddress): self
1232
    {
1233 6
        $this->deliveryAddress = $deliveryAddress;
1234
1235 6
        return $this;
1236
    }
1237
1238
    /**
1239
     * @return string
1240
     */
1241 3
    public function getDeliveryAddress2(): ?string
1242
    {
1243 3
        return $this->deliveryAddress2;
1244
    }
1245
1246
    /**
1247
     * @param string $deliveryAddress2
1248
     *
1249
     * @return Payment
1250
     */
1251 6
    public function setDeliveryAddress2(string $deliveryAddress2): self
1252
    {
1253 6
        $this->deliveryAddress2 = $deliveryAddress2;
1254
1255 6
        return $this;
1256
    }
1257
1258
    /**
1259
     * @return string
1260
     */
1261 3
    public function getDeliveryZipCode(): ?string
1262
    {
1263 3
        return $this->deliveryZipCode;
1264
    }
1265
1266
    /**
1267
     * @param string $deliveryZipCode
1268
     *
1269
     * @return Payment
1270
     */
1271 6
    public function setDeliveryZipCode(string $deliveryZipCode): self
1272
    {
1273 6
        $this->deliveryZipCode = $deliveryZipCode;
1274
1275 6
        return $this;
1276
    }
1277
1278
    /**
1279
     * @return string
1280
     */
1281 3
    public function getDeliveryCity(): ?string
1282
    {
1283 3
        return $this->deliveryCity;
1284
    }
1285
1286
    /**
1287
     * @param string $deliveryCity
1288
     *
1289
     * @return Payment
1290
     */
1291 6
    public function setDeliveryCity(string $deliveryCity): self
1292
    {
1293 6
        $this->deliveryCity = $deliveryCity;
1294
1295 6
        return $this;
1296
    }
1297
1298
    /**
1299
     * @return int
1300
     */
1301 3
    public function getDeliveryCountryID()
1302
    {
1303 3
        return $this->deliveryCountryID;
1304
    }
1305
1306
    /**
1307
     * @param int $deliveryCountryID
1308
     *
1309
     * @return Payment
1310
     */
1311 6
    public function setDeliveryCountryID(int $deliveryCountryID): self
1312
    {
1313 6
        $this->deliveryCountryID = $deliveryCountryID;
1314
1315 6
        return $this;
1316
    }
1317
1318
    /**
1319
     * @return string
1320
     */
1321 3
    public function getDeliveryCountry(): ?string
1322
    {
1323 3
        return $this->deliveryCountry;
1324
    }
1325
1326
    /**
1327
     * @param string $deliveryCountry
1328
     *
1329
     * @return Payment
1330
     */
1331 6
    public function setDeliveryCountry(string $deliveryCountry): self
1332
    {
1333 6
        $this->deliveryCountry = $deliveryCountry;
1334
1335 6
        return $this;
1336
    }
1337
1338
    /**
1339
     * @return string
1340
     */
1341 3
    public function getDeliveryPhone(): ?string
1342
    {
1343 3
        return $this->deliveryPhone;
1344
    }
1345
1346
    /**
1347
     * @param string $deliveryPhone
1348
     *
1349
     * @return Payment
1350
     */
1351 6
    public function setDeliveryPhone(string $deliveryPhone): self
1352
    {
1353 6
        $this->deliveryPhone = $deliveryPhone;
1354
1355 6
        return $this;
1356
    }
1357
1358
    /**
1359
     * @return string
1360
     */
1361 3
    public function getDeliveryFax(): ?string
1362
    {
1363 3
        return $this->deliveryFax;
1364
    }
1365
1366
    /**
1367
     * @param string $deliveryFax
1368
     *
1369
     * @return Payment
1370
     */
1371 6
    public function setDeliveryFax(string $deliveryFax): self
1372
    {
1373 6
        $this->deliveryFax = $deliveryFax;
1374
1375 6
        return $this;
1376
    }
1377
1378
    /**
1379
     * @return string
1380
     */
1381 3
    public function getDeliveryEmail(): ?string
1382
    {
1383 3
        return $this->deliveryEmail;
1384
    }
1385
1386
    /**
1387
     * @param string $deliveryEmail
1388
     *
1389
     * @return Payment
1390
     */
1391 6
    public function setDeliveryEmail(string $deliveryEmail): self
1392
    {
1393 6
        $this->deliveryEmail = $deliveryEmail;
1394
1395 6
        return $this;
1396
    }
1397
1398
    /**
1399
     * @return string
1400
     */
1401 3
    public function getDeliveryEan(): ?string
1402
    {
1403 3
        return $this->deliveryEan;
1404
    }
1405
1406
    /**
1407
     * @param string $deliveryEan
1408
     *
1409
     * @return Payment
1410
     */
1411 6
    public function setDeliveryEan(string $deliveryEan): self
1412
    {
1413 6
        $this->deliveryEan = $deliveryEan;
1414
1415 6
        return $this;
1416
    }
1417
1418
    /**
1419
     * @return string
1420
     */
1421 3
    public function getShippingMethod(): ?string
1422
    {
1423 3
        return $this->shippingMethod;
1424
    }
1425
1426
    /**
1427
     * @param string $shippingMethod
1428
     *
1429
     * @return Payment
1430
     */
1431 6
    public function setShippingMethod(string $shippingMethod): self
1432
    {
1433 6
        $this->shippingMethod = $shippingMethod;
1434
1435 6
        return $this;
1436
    }
1437
1438
    /**
1439
     * @return int
1440
     */
1441 3
    public function getShippingMethodId(): ?int
1442
    {
1443 3
        return $this->shippingMethodId;
1444
    }
1445
1446
    /**
1447
     * @param int $shippingMethodId
1448
     * @return Payment
1449
     */
1450 6
    public function setShippingMethodId(int $shippingMethodId) : self
1451
    {
1452 6
        $this->shippingMethodId = $shippingMethodId;
1453 6
        return $this;
1454
    }
1455
1456
    /**
1457
     * @return Money
1458
     */
1459 3
    public function getShippingFee(): ?Money
1460
    {
1461 3
        return $this->shippingFee;
1462
    }
1463
1464
    /**
1465
     * @param Money $shippingFee
1466
     *
1467
     * @return Payment
1468
     */
1469 3
    public function setShippingFee(Money $shippingFee): self
1470
    {
1471 3
        $this->shippingFee = $shippingFee;
1472
1473 3
        return $this;
1474
    }
1475
1476
    /**
1477
     * @return string
1478
     */
1479 3
    public function getPaymentMethod(): ?string
1480
    {
1481 3
        return $this->paymentMethod;
1482
    }
1483
1484
    /**
1485
     * @param string $paymentMethod
1486
     *
1487
     * @return Payment
1488
     */
1489 6
    public function setPaymentMethod(string $paymentMethod): self
1490
    {
1491 6
        $this->paymentMethod = $paymentMethod;
1492
1493 6
        return $this;
1494
    }
1495
1496
    /**
1497
     * @return int
1498
     */
1499 3
    public function getPaymentMethodId(): ?int
1500
    {
1501 3
        return $this->paymentMethodId;
1502
    }
1503
1504
    /**
1505
     * @param int $paymentMethodId
1506
     * @return Payment
1507
     */
1508 6
    public function setPaymentMethodId(int $paymentMethodId) : self
1509
    {
1510 6
        $this->paymentMethodId = $paymentMethodId;
1511 6
        return $this;
1512
    }
1513
1514
    /**
1515
     * @return Money
1516
     */
1517 3
    public function getPaymentFee(): ?Money
1518
    {
1519 3
        return $this->paymentFee;
1520
    }
1521
1522
    /**
1523
     * @param Money $paymentFee
1524
     *
1525
     * @return Payment
1526
     */
1527 3
    public function setPaymentFee(Money $paymentFee): self
1528
    {
1529 3
        $this->paymentFee = $paymentFee;
1530
1531 3
        return $this;
1532
    }
1533
1534
    /**
1535
     * @return string
1536
     */
1537 3
    public function getLoadBalancerRealIp(): ?string
1538
    {
1539 3
        return $this->loadBalancerRealIp;
1540
    }
1541
1542
    /**
1543
     * @param string $loadBalancerRealIp
1544
     *
1545
     * @return Payment
1546
     */
1547 6
    public function setLoadBalancerRealIp(string $loadBalancerRealIp): self
1548
    {
1549 6
        $this->loadBalancerRealIp = $loadBalancerRealIp;
1550
1551 6
        return $this;
1552
    }
1553
1554
    /**
1555
     * @return string
1556
     */
1557 3
    public function getReferrer(): ?string
1558
    {
1559 3
        return $this->referrer;
1560
    }
1561
1562
    /**
1563
     * @param string $referrer
1564
     *
1565
     * @return Payment
1566
     */
1567 6
    public function setReferrer(string $referrer): self
1568
    {
1569 6
        $this->referrer = $referrer;
1570
1571 6
        return $this;
1572
    }
1573
1574
    /**
1575
     * @return PaymentLine[]|iterable
1576
     */
1577 6
    public function getPaymentLines(): iterable
1578
    {
1579 6
        return $this->paymentLines;
1580
    }
1581
1582
    /**
1583
     * @param PaymentLine[]|iterable $paymentLines
1584
     *
1585
     * @return Payment
1586
     */
1587 3
    public function setPaymentLines(iterable $paymentLines): self
1588
    {
1589 3
        $this->paymentLines = $paymentLines;
0 ignored issues
show
Documentation Bug introduced by
It seems like $paymentLines can also be of type object<Loevgaard\Dandomain\Pay\Model\iterable>. However, the property $paymentLines is declared as type array<integer,object<Loe...Pay\Model\PaymentLine>>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
1590
1591 3
        return $this;
1592
    }
1593
1594
    /**
1595
     * @param PaymentLine $paymentLine
1596
     *
1597
     * @return Payment
1598
     */
1599 3
    public function addPaymentLine(PaymentLine $paymentLine): self
1600
    {
1601 3
        $paymentLine->setPayment($this);
1602 3
        $this->paymentLines[] = $paymentLine;
1603
1604 3
        return $this;
1605
    }
1606
1607
    /**
1608
     * Returns the default currency for this payment
1609
     *
1610
     * @return null|string
1611
     */
1612 6
    protected function getCurrency() : ?string
1613
    {
1614 6
        return $this->currencySymbol;
1615
    }
1616
1617
    /**
1618
     * A helper method for creating a Money object from a float based on the shared currency
1619
     *
1620
     * @param int $amount
1621
     * @return Money|null
1622
     */
1623 6
    protected function createMoney(int $amount = 0) : ?Money
1624
    {
1625 6
        if (!$this->getCurrency()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getCurrency() of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1626 3
            return null;
1627
        }
1628
1629 3
        return new Money($amount, new Currency($this->getCurrency()));
1630
    }
1631
1632
    /**
1633
     * A helper method for creating a Money object from a float based on the shared currency
1634
     *
1635
     * The float can be any format, i.e. 1.50 or 1,50
1636
     *
1637
     * @param string $amount
1638
     * @return Money|null
1639
     */
1640 6
    protected function createMoneyFromFloat(string $amount = '0.00') : ?Money
1641
    {
1642 6
        $amount = static::priceStringToInt((string)$amount);
1643 6
        return $this->createMoney($amount);
1644
    }
1645
}
1646