Completed
Push — master ( 3ee5ff...5084e8 )
by Joachim
12:38
created

CustomerInfo::validate()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 0
crap 1
1
<?php
2
namespace Loevgaard\AltaPay\Payload\PaymentRequest;
3
4
use Assert\Assert;
5
use Loevgaard\AltaPay\Payload\Payload;
6
7
class CustomerInfo extends Payload implements CustomerInfoInterface
8
{
9
    const GENDER_MALE = 'male';
10
    const GENDER_MALE_2 = 'm';
11
    const GENDER_FEMALE = 'female';
12
    const GENDER_FEMALE_2 = 'f';
13
14
    /**
15
     * @var string
16
     */
17
    private $bankName;
18
19
    /**
20
     * @var string
21
     */
22
    private $bankPhone;
23
24
    /**
25
     * @var string
26
     */
27
    private $billingAddress;
28
29
    /**
30
     * @var string
31
     */
32
    private $billingCity;
33
34
    /**
35
     * @var string
36
     */
37
    private $billingCountry;
38
39
    /**
40
     * @var string
41
     */
42
    private $billingFirstName;
43
44
    /**
45
     * @var string
46
     */
47
    private $billingLastName;
48
49
    /**
50
     * @var string
51
     */
52
    private $billingPostal;
53
54
    /**
55
     * @var string
56
     */
57
    private $billingRegion;
58
59
    /**
60
     * @var \DateTimeInterface
61
     */
62
    private $birthDate;
63
64
    /**
65
     * @var string
66
     */
67
    private $customerPhone;
68
69
    /**
70
     * @var string
71
     */
72
    private $email;
73
74
    /**
75
     * @var string
76
     */
77
    private $gender;
78
79
    /**
80
     * @var string
81
     */
82
    private $shippingAddress;
83
84
    /**
85
     * @var string
86
     */
87
    private $shippingCity;
88
89
    /**
90
     * @var string
91
     */
92
    private $shippingCountry;
93
94
    /**
95
     * @var string
96
     */
97
    private $shippingFirstName;
98
99
    /**
100
     * @var string
101
     */
102
    private $shippingLastName;
103
104
    /**
105
     * @var string
106
     */
107
    private $shippingPostal;
108
109
    /**
110
     * @var string
111
     */
112
    private $shippingRegion;
113
114
    /**
115
     * @var string
116
     */
117
    private $username;
118
119
    public function getPayload() : array
120
    {
121
        $payload = [
122
            'bank_name' => $this->getBankName(),
123
            'bank_phone' => $this->getBankPhone(),
124
            'billing_address' => $this->getBillingAddress(),
125
            'billing_city' => $this->getBillingCity(),
126
            'billing_country' => $this->getBillingCountry(),
127
            'billing_firstname' => $this->getBillingFirstName(),
128
            'billing_lastname' => $this->getBillingLastName(),
129
            'billing_postal' => $this->getBillingPostal(),
130
            'billing_region' => $this->getBillingRegion(),
131
            'birthdate' => $this->getBirthDate() ? $this->getBirthDate()->format('Y-m-d') : null,
132
            'customer_phone' => $this->getCustomerPhone(),
133
            'email' => $this->getEmail(),
134
            'gender' => $this->getGender(),
135
            'shipping_address' => $this->getShippingAddress(),
136
            'shipping_city' => $this->getShippingCity(),
137
            'shipping_country' => $this->getShippingCountry(),
138
            'shipping_firstname' => $this->getShippingFirstName(),
139
            'shipping_lastname' => $this->getShippingLastName(),
140
            'shipping_postal' => $this->getShippingPostal(),
141 6
            'shipping_region' => $this->getShippingRegion(),
142
            'username' => $this->getUsername(),
143
        ];
144
145
        $this->validate();
146
147
        return static::simplePayload($payload);
148
    }
149
150
    public function validate()
151
    {
152
        Assert::thatNullOr($this->bankName)->string();
153
        Assert::thatNullOr($this->bankPhone)->string();
154
        Assert::thatNullOr($this->billingAddress)->string();
155
        Assert::thatNullOr($this->billingCity)->string();
156
        Assert::thatNullOr($this->billingCountry)->string();
157
        Assert::thatNullOr($this->billingFirstName)->string();
158
        Assert::thatNullOr($this->billingLastName)->string();
159
        Assert::thatNullOr($this->billingPostal)->string();
160
        Assert::thatNullOr($this->billingRegion)->string();
161
        Assert::thatNullOr($this->birthDate)->isInstanceOf(\DateTimeInterface::class);
162
        Assert::thatNullOr($this->customerPhone)->string();
163
        Assert::thatNullOr($this->email)->email();
164 6
        Assert::thatNullOr($this->gender)->inArray(static::getGenders());
165 6
        Assert::thatNullOr($this->shippingAddress)->string();
166 6
        Assert::thatNullOr($this->shippingCity)->string();
167 6
        Assert::thatNullOr($this->shippingCountry)->string();
168 6
        Assert::thatNullOr($this->shippingFirstName)->string();
169 6
        Assert::thatNullOr($this->shippingLastName)->string();
170 6
        Assert::thatNullOr($this->shippingPostal)->string();
171 6
        Assert::thatNullOr($this->shippingRegion)->string();
172 6
        Assert::thatNullOr($this->username)->string();
173 6
    }
174 6
175 6
    public static function getGenders() : array
176 6
    {
177 6
        return [
178 6
            self::GENDER_MALE,
179 6
            self::GENDER_MALE_2,
180 6
            self::GENDER_FEMALE,
181 6
            self::GENDER_FEMALE_2,
182 6
        ];
183 6
    }
184 6
185 6
    /**
186
     * @return string
187
     */
188 6
    public function getBankName() : ?string
189
    {
190
        return $this->bankName;
191 6
    }
192 6
193 6
    /**
194 6
     * @param string $bankName
195 6
     * @return CustomerInfo
196 6
     */
197 6
    public function setBankName(string $bankName) : self
198 6
    {
199 6
        $this->bankName = $bankName;
200 6
        return $this;
201 6
    }
202 6
203 6
    /**
204 6
     * @return string
205 6
     */
206 6
    public function getBankPhone() : ?string
207 6
    {
208 6
        return $this->bankPhone;
209 6
    }
210 6
211 6
    /**
212 4
     * @param string $bankPhone
213
     * @return CustomerInfo
214 6
     */
215
    public function setBankPhone(string $bankPhone) : self
216
    {
217 6
        $this->bankPhone = $bankPhone;
218
        return $this;
219
    }
220 6
221 6
    /**
222 6
     * @return string
223 6
     */
224 4
    public function getBillingAddress() : ?string
225
    {
226
        return $this->billingAddress;
227
    }
228
229
    /**
230 6
     * @param string $billingAddress
231
     * @return CustomerInfo
232 6
     */
233
    public function setBillingAddress(string $billingAddress) : self
234
    {
235
        $this->billingAddress = $billingAddress;
236
        return $this;
237
    }
238
239 6
    /**
240
     * @return string
241 6
     */
242 6
    public function getBillingCity() : ?string
243 6
    {
244
        return $this->billingCity;
245
    }
246
247
    /**
248
     * @param string $billingCity
249 6
     * @return CustomerInfo
250
     */
251 6
    public function setBillingCity(string $billingCity) : self
252
    {
253
        $this->billingCity = $billingCity;
254
        return $this;
255
    }
256
257
    /**
258 6
     * @return string
259
     */
260 6
    public function getBillingCountry() : ?string
261 6
    {
262 6
        return $this->billingCountry;
263
    }
264
265
    /**
266
     * @param string $billingCountry
267
     * @return CustomerInfo
268 6
     */
269
    public function setBillingCountry(string $billingCountry) : self
270 6
    {
271
        $this->billingCountry = $billingCountry;
272
        return $this;
273
    }
274
275
    /**
276
     * @return string
277 6
     */
278
    public function getBillingFirstName() : ?string
279 6
    {
280 6
        return $this->billingFirstName;
281 6
    }
282
283
    /**
284
     * @param string $billingFirstName
285
     * @return CustomerInfo
286
     */
287 6
    public function setBillingFirstName(string $billingFirstName) : self
288
    {
289 6
        $this->billingFirstName = $billingFirstName;
290
        return $this;
291
    }
292
293
    /**
294
     * @return string
295
     */
296 6
    public function getBillingLastName() : ?string
297
    {
298 6
        return $this->billingLastName;
299 6
    }
300 6
301
    /**
302
     * @param string $billingLastName
303
     * @return CustomerInfo
304
     */
305
    public function setBillingLastName(string $billingLastName) : self
306 6
    {
307
        $this->billingLastName = $billingLastName;
308 6
        return $this;
309
    }
310
311
    /**
312
     * @return string
313
     */
314
    public function getBillingPostal() : ?string
315 6
    {
316
        return $this->billingPostal;
317 6
    }
318 6
319 6
    /**
320
     * @param string $billingPostal
321
     * @return CustomerInfo
322
     */
323
    public function setBillingPostal(string $billingPostal) : self
324
    {
325 6
        $this->billingPostal = $billingPostal;
326
        return $this;
327 6
    }
328
329
    /**
330
     * @return string
331
     */
332
    public function getBillingRegion() : ?string
333
    {
334 6
        return $this->billingRegion;
335
    }
336 6
337 6
    /**
338 6
     * @param string $billingRegion
339
     * @return CustomerInfo
340
     */
341
    public function setBillingRegion(string $billingRegion) : self
342
    {
343
        $this->billingRegion = $billingRegion;
344 6
        return $this;
345
    }
346 6
347
    /**
348
     * @return \DateTimeInterface
349
     */
350
    public function getBirthDate()
351
    {
352
        return $this->birthDate;
353 6
    }
354
355 6
    /**
356 6
     * @param \DateTimeInterface $birthDate
357 6
     * @return CustomerInfo
358
     */
359
    public function setBirthDate(\DateTimeInterface $birthDate) : self
360
    {
361
        $this->birthDate = $birthDate;
362
        return $this;
363 6
    }
364
365 6
    /**
366
     * @return string
367
     */
368
    public function getCustomerPhone() : ?string
369
    {
370
        return $this->customerPhone;
371
    }
372 6
373
    /**
374 6
     * @param string $customerPhone
375 6
     * @return CustomerInfo
376 6
     */
377
    public function setCustomerPhone(string $customerPhone) : self
378
    {
379
        $this->customerPhone = $customerPhone;
380
        return $this;
381
    }
382 6
383
    /**
384 6
     * @return string
385
     */
386
    public function getEmail() : ?string
387
    {
388
        return $this->email;
389
    }
390
391 6
    /**
392
     * @param string $email
393 6
     * @return CustomerInfo
394 6
     */
395 6
    public function setEmail(string $email) : self
396
    {
397
        $this->email = $email;
398
        return $this;
399
    }
400
401 6
    /**
402
     * @return string
403 6
     */
404
    public function getGender() : ?string
405
    {
406
        return $this->gender;
407
    }
408
409
    /**
410 6
     * @param string $gender
411
     * @return CustomerInfo
412 6
     */
413 6
    public function setGender(string $gender) : self
414 6
    {
415
        Assert::that($gender)->nullOr()->inArray(static::getGenders());
416
        $this->gender = $gender;
417
        return $this;
418
    }
419
420 6
    /**
421
     * @return string
422 6
     */
423
    public function getShippingAddress() : ?string
424
    {
425
        return $this->shippingAddress;
426
    }
427
428
    /**
429 6
     * @param string $shippingAddress
430
     * @return CustomerInfo
431 6
     */
432 6
    public function setShippingAddress(string $shippingAddress) : self
433 6
    {
434
        $this->shippingAddress = $shippingAddress;
435
        return $this;
436
    }
437
438
    /**
439 6
     * @return string
440
     */
441 6
    public function getShippingCity() : ?string
442
    {
443
        return $this->shippingCity;
444
    }
445
446
    /**
447
     * @param string $shippingCity
448 6
     * @return CustomerInfo
449
     */
450 6
    public function setShippingCity(string $shippingCity) : self
451 6
    {
452 6
        $this->shippingCity = $shippingCity;
453
        return $this;
454
    }
455
456
    /**
457
     * @return string
458 6
     */
459
    public function getShippingCountry() : ?string
460 6
    {
461
        return $this->shippingCountry;
462
    }
463
464
    /**
465
     * @param string $shippingCountry
466
     * @return CustomerInfo
467 6
     */
468
    public function setShippingCountry(string $shippingCountry) : self
469 6
    {
470 6
        $this->shippingCountry = $shippingCountry;
471 6
        return $this;
472
    }
473
474
    /**
475
     * @return string
476
     */
477 6
    public function getShippingFirstName() : ?string
478
    {
479 6
        return $this->shippingFirstName;
480
    }
481
482
    /**
483
     * @param string $shippingFirstName
484
     * @return CustomerInfo
485
     */
486 6
    public function setShippingFirstName(string $shippingFirstName) : self
487
    {
488 6
        $this->shippingFirstName = $shippingFirstName;
489 6
        return $this;
490 6
    }
491
492
    /**
493
     * @return string
494
     */
495
    public function getShippingLastName() : ?string
496 6
    {
497
        return $this->shippingLastName;
498 6
    }
499
500
    /**
501
     * @param string $shippingLastName
502
     * @return CustomerInfo
503
     */
504
    public function setShippingLastName(string $shippingLastName) : self
505 6
    {
506
        $this->shippingLastName = $shippingLastName;
507 6
        return $this;
508 6
    }
509 6
510
    /**
511
     * @return string
512
     */
513
    public function getShippingPostal() : ?string
514
    {
515 6
        return $this->shippingPostal;
516
    }
517 6
518
    /**
519
     * @param string $shippingPostal
520
     * @return CustomerInfo
521
     */
522
    public function setShippingPostal(string $shippingPostal) : self
523
    {
524 6
        $this->shippingPostal = $shippingPostal;
525
        return $this;
526 6
    }
527 6
528 6
    /**
529
     * @return string
530
     */
531
    public function getShippingRegion() : ?string
532
    {
533
        return $this->shippingRegion;
534 6
    }
535
536 6
    /**
537
     * @param string $shippingRegion
538
     * @return CustomerInfo
539
     */
540
    public function setShippingRegion(string $shippingRegion) : self
541
    {
542
        $this->shippingRegion = $shippingRegion;
543 6
        return $this;
544
    }
545 6
546 6
    /**
547 6
     * @return string
548
     */
549
    public function getUsername() : ?string
550
    {
551
        return $this->username;
552
    }
553 6
554
    /**
555 6
     * @param string $username
556
     * @return CustomerInfo
557
     */
558
    public function setUsername(string $username) : self
559
    {
560
        $this->username = $username;
561
        return $this;
562 6
    }
563
}
564