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

Customer   F

Complexity

Total Complexity 61

Size/Duplication

Total Lines 789
Duplicated Lines 2.92 %

Importance

Changes 0
Metric Value
dl 23
loc 789
rs 3.2432
c 0
b 0
f 0
wmc 61

61 Methods

Rating   Name   Duplication   Size   Complexity  
A getCustomerGroupId() 0 3 1
A getAddress2() 0 3 1
A setCustomerGroupId() 0 4 1
A getState() 0 3 1
A getCustomerType() 0 3 1
A setReservedField1() 0 4 1
A getAttention() 0 3 1
A setCountry() 0 4 1
A getReservedField1() 0 3 1
A setExternalId() 0 4 1
A getCreatedDate() 0 3 1
A getPhone() 0 3 1
A getReservedField2() 0 3 1
A setPhone() 0 4 1
A setCustomerType() 0 4 1
A setEmail() 0 4 1
A getReservedField3() 0 3 1
A getCountryId() 0 3 1
A getLoginCount() 0 3 1
A setB2b() 0 4 1
A setLoginCount() 0 4 1
A setState() 0 4 1
A populateFromApiResponse() 22 22 1
A setReservedField2() 0 4 1
A setAttention() 0 4 1
A setAddress() 0 4 1
A setCity() 0 4 1
A getZipCode() 0 3 1
A getName() 0 3 1
A getCvr() 0 3 1
A getEan() 0 3 1
A setPassword() 0 4 1
A setFax() 0 4 1
A setName() 0 4 1
A getCity() 0 3 1
A getPassword() 0 3 1
A getAddress() 0 3 1
A getId() 0 3 1
A setLastLoginDate() 0 4 1
A setReservedField3() 0 4 1
A getReservedField5() 0 3 1
A setZipCode() 0 4 1
A getCountry() 0 3 1
A setCvr() 0 4 1
A getComments() 0 3 1
A getExternalId() 0 3 1
A getB2bGroupId() 0 3 1
A setReservedField4() 0 4 1
A getLastLoginDate() 0 3 1
A setAddress2() 0 4 1
A getFax() 0 3 1
A getReservedField4() 0 3 1
A setComments() 0 4 1
A getB2b() 0 3 1
A getEmail() 0 3 1
A setEan() 0 4 1
A setB2bGroupId() 0 4 1
A setCountryId() 0 4 1
A setId() 0 4 1
A setCreatedDate() 0 4 1
A setReservedField5() 0 4 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Customer 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 Customer, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Loevgaard\DandomainFoundation\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Loevgaard\DandomainFoundation;
7
use Loevgaard\DandomainFoundation\Entity\Generated\CustomerInterface;
8
use Loevgaard\DandomainFoundation\Entity\Generated\CustomerTraits;
9
10
/**
11
 * @ORM\Entity()
12
 * @ORM\Table(name="loevgaard_dandomain_customers")
13
 *
14
 * @todo missing properties, see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/CustomerService/help/operations/GetCustomer
15
 */
16
class Customer implements CustomerInterface
17
{
18
    use CustomerTraits;
19
20
    /**
21
     * @var int
22
     *
23
     * @ORM\Id
24
     * @ORM\GeneratedValue
25
     * @ORM\Column(type="integer")
26
     **/
27
    protected $id;
28
29
    /**
30
     * This is the customer id in Dandomain
31
     *
32
     * @var int
33
     *
34
     * @ORM\Column(type="integer", unique=true)
35
     */
36
    protected $externalId;
37
38
    /**
39
     * @var string|null
40
     *
41
     * @ORM\Column(nullable=true, type="string")
42
     */
43
    protected $address;
44
45
    /**
46
     * @var string|null
47
     *
48
     * @ORM\Column(nullable=true, type="string")
49
     */
50
    protected $address2;
51
52
    /**
53
     * @var string|null
54
     *
55
     * @ORM\Column(nullable=true, type="string")
56
     */
57
    protected $attention;
58
59
    /**
60
     * @var string|null
61
     *
62
     * @ORM\Column(nullable=true, type="string")
63
     */
64
    protected $city;
65
66
    /**
67
     * @var string|null
68
     *
69
     * @ORM\Column(nullable=true, type="string")
70
     */
71
    protected $country;
72
73
    /**
74
     * @var int|null
75
     *
76
     * @ORM\Column(nullable=true, type="integer")
77
     */
78
    protected $countryId;
79
80
    /**
81
     * @var string|null
82
     *
83
     * @ORM\Column(nullable=true, type="string")
84
     */
85
    protected $ean;
86
87
    /**
88
     * @var string|null
89
     *
90
     * @ORM\Column(nullable=true, type="string")
91
     */
92
    protected $email;
93
94
    /**
95
     * @var string|null
96
     *
97
     * @ORM\Column(nullable=true, type="string")
98
     */
99
    protected $fax;
100
101
    /**
102
     * @var string|null
103
     *
104
     * @ORM\Column(nullable=true, type="string")
105
     */
106
    protected $name;
107
108
    /**
109
     * @var string|null
110
     *
111
     * @ORM\Column(nullable=true, type="string")
112
     */
113
    protected $phone;
114
115
    /**
116
     * @var string|null
117
     *
118
     * @ORM\Column(nullable=true, type="string")
119
     */
120
    protected $state;
121
122
    /**
123
     * @var string|null
124
     *
125
     * @ORM\Column(nullable=true, type="string")
126
     */
127
    protected $zipCode;
128
129
    /**
130
     * @var string|null
131
     *
132
     * @ORM\Column(nullable=true, type="string")
133
     */
134
    protected $cvr;
135
136
    /**
137
     * @var string|null
138
     *
139
     * @ORM\Column(nullable=true, type="string")
140
     */
141
    protected $b2bGroupId;
142
143
    /**
144
     * @var string|null
145
     *
146
     * @ORM\Column(nullable=true, type="text")
147
     */
148
    protected $comments;
149
150
    /**
151
     * @var \DateTimeImmutable|null
152
     *
153
     * @ORM\Column(nullable=true, type="datetime_immutable")
154
     */
155
    protected $createdDate;
156
157
    /**
158
     * @var string|null
159
     *
160
     * @ORM\Column(nullable=true, type="string")
161
     */
162
    protected $customerGroupId;
163
164
    /**
165
     * @var string|null
166
     *
167
     * @ORM\Column(nullable=true, type="string")
168
     */
169
    protected $customerType;
170
171
    /**
172
     * @var bool|null
173
     *
174
     * @ORM\Column(nullable=true, type="boolean")
175
     */
176
    protected $b2b;
177
178
    /**
179
     * @var \DateTimeImmutable|null
180
     *
181
     * @ORM\Column(nullable=true, type="datetime_immutable")
182
     */
183
    protected $lastLoginDate;
184
185
    /**
186
     * @var int|null
187
     *
188
     * @ORM\Column(nullable=true, type="integer")
189
     */
190
    protected $loginCount;
191
192
    /**
193
     * @var string|null
194
     *
195
     * @ORM\Column(nullable=true, type="string")
196
     */
197
    protected $password;
198
199
    /**
200
     * @var string|null
201
     *
202
     * @ORM\Column(nullable=true, type="string")
203
     */
204
    protected $reservedField1;
205
206
    /**
207
     * @var string|null
208
     *
209
     * @ORM\Column(nullable=true, type="string")
210
     */
211
    protected $reservedField2;
212
213
    /**
214
     * @var string|null
215
     *
216
     * @ORM\Column(nullable=true, type="string")
217
     */
218
    protected $reservedField3;
219
220
    /**
221
     * @var string|null
222
     *
223
     * @ORM\Column(nullable=true, type="string")
224
     */
225
    protected $reservedField4;
226
227
    /**
228
     * @var string|null
229
     *
230
     * @ORM\Column(nullable=true, type="string")
231
     */
232
    protected $reservedField5;
233
234
    /**
235
     * Populates a customer based on the response from the Dandomain API
236
     *
237
     * See the properties here:
238
     * http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/CustomerService/help/operations/GetCustomer
239
     *
240
     * @param \stdClass|array $data
241
     * @return CustomerInterface
242
     */
243 View Code Duplication
    public function populateFromApiResponse($data) : CustomerInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
244
    {
245
        $data = DandomainFoundation\objectToArray($data);
246
247
        $this
248
            ->setExternalId($data['id'])
249
            ->setAddress($data['address'])
250
            ->setAddress2($data['address2'])
251
            ->setAttention($data['attention'])
252
            ->setCity($data['city'])
253
            ->setCountry($data['country'])
254
            ->setCountryId($data['countryId'])
255
            ->setEan($data['ean'])
256
            ->setEmail($data['email'])
257
            ->setFax($data['fax'])
258
            ->setName($data['name'])
259
            ->setPhone($data['phone'])
260
            ->setState($data['state'])
261
            ->setZipCode($data['zipCode'])
262
        ;
263
264
        return $this;
265
    }
266
267
    /**
268
     * @return int
269
     */
270
    public function getId(): int
271
    {
272
        return (int)$this->id;
273
    }
274
275
    /**
276
     * @param int $id
277
     * @return CustomerInterface
278
     */
279
    public function setId($id)
280
    {
281
        $this->id = $id;
282
        return $this;
283
    }
284
285
    /**
286
     * @return int
287
     */
288
    public function getExternalId(): int
289
    {
290
        return (int)$this->externalId;
291
    }
292
293
    /**
294
     * @param int $externalId
295
     * @return CustomerInterface
296
     */
297
    public function setExternalId($externalId)
298
    {
299
        $this->externalId = $externalId;
300
        return $this;
301
    }
302
303
    /**
304
     * @return null|string
305
     */
306
    public function getAddress()
307
    {
308
        return $this->address;
309
    }
310
311
    /**
312
     * @param null|string $address
313
     * @return CustomerInterface
314
     */
315
    public function setAddress($address)
316
    {
317
        $this->address = $address;
318
        return $this;
319
    }
320
321
    /**
322
     * @return null|string
323
     */
324
    public function getAddress2()
325
    {
326
        return $this->address2;
327
    }
328
329
    /**
330
     * @param null|string $address2
331
     * @return CustomerInterface
332
     */
333
    public function setAddress2($address2)
334
    {
335
        $this->address2 = $address2;
336
        return $this;
337
    }
338
339
    /**
340
     * @return null|string
341
     */
342
    public function getAttention()
343
    {
344
        return $this->attention;
345
    }
346
347
    /**
348
     * @param null|string $attention
349
     * @return CustomerInterface
350
     */
351
    public function setAttention($attention)
352
    {
353
        $this->attention = $attention;
354
        return $this;
355
    }
356
357
    /**
358
     * @return null|string
359
     */
360
    public function getCity()
361
    {
362
        return $this->city;
363
    }
364
365
    /**
366
     * @param null|string $city
367
     * @return CustomerInterface
368
     */
369
    public function setCity($city)
370
    {
371
        $this->city = $city;
372
        return $this;
373
    }
374
375
    /**
376
     * @return null|string
377
     */
378
    public function getCountry()
379
    {
380
        return $this->country;
381
    }
382
383
    /**
384
     * @param null|string $country
385
     * @return CustomerInterface
386
     */
387
    public function setCountry($country)
388
    {
389
        $this->country = $country;
390
        return $this;
391
    }
392
393
    /**
394
     * @return null|string
395
     */
396
    public function getEan()
397
    {
398
        return $this->ean;
399
    }
400
401
    /**
402
     * @param null|string $ean
403
     * @return CustomerInterface
404
     */
405
    public function setEan($ean)
406
    {
407
        $this->ean = $ean;
408
        return $this;
409
    }
410
411
    /**
412
     * @return null|string
413
     */
414
    public function getEmail()
415
    {
416
        return $this->email;
417
    }
418
419
    /**
420
     * @param null|string $email
421
     * @return CustomerInterface
422
     */
423
    public function setEmail($email)
424
    {
425
        $this->email = $email;
426
        return $this;
427
    }
428
429
    /**
430
     * @return null|string
431
     */
432
    public function getFax()
433
    {
434
        return $this->fax;
435
    }
436
437
    /**
438
     * @param null|string $fax
439
     * @return CustomerInterface
440
     */
441
    public function setFax($fax)
442
    {
443
        $this->fax = $fax;
444
        return $this;
445
    }
446
447
    /**
448
     * @return null|string
449
     */
450
    public function getName()
451
    {
452
        return $this->name;
453
    }
454
455
    /**
456
     * @param null|string $name
457
     * @return CustomerInterface
458
     */
459
    public function setName($name)
460
    {
461
        $this->name = $name;
462
        return $this;
463
    }
464
465
    /**
466
     * @return null|string
467
     */
468
    public function getPhone()
469
    {
470
        return $this->phone;
471
    }
472
473
    /**
474
     * @param null|string $phone
475
     * @return CustomerInterface
476
     */
477
    public function setPhone($phone)
478
    {
479
        $this->phone = $phone;
480
        return $this;
481
    }
482
483
    /**
484
     * @return null|string
485
     */
486
    public function getState()
487
    {
488
        return $this->state;
489
    }
490
491
    /**
492
     * @param null|string $state
493
     * @return CustomerInterface
494
     */
495
    public function setState($state)
496
    {
497
        $this->state = $state;
498
        return $this;
499
    }
500
501
    /**
502
     * @return null|string
503
     */
504
    public function getZipCode()
505
    {
506
        return $this->zipCode;
507
    }
508
509
    /**
510
     * @param null|string $zipCode
511
     * @return CustomerInterface
512
     */
513
    public function setZipCode($zipCode)
514
    {
515
        $this->zipCode = $zipCode;
516
        return $this;
517
    }
518
519
    /**
520
     * @return null|string
521
     */
522
    public function getCvr()
523
    {
524
        return $this->cvr;
525
    }
526
527
    /**
528
     * @param null|string $cvr
529
     * @return CustomerInterface
530
     */
531
    public function setCvr($cvr)
532
    {
533
        $this->cvr = $cvr;
534
        return $this;
535
    }
536
537
    /**
538
     * @return null|string
539
     */
540
    public function getB2bGroupId()
541
    {
542
        return $this->b2bGroupId;
543
    }
544
545
    /**
546
     * @param null|string $b2bGroupId
547
     * @return CustomerInterface
548
     */
549
    public function setB2bGroupId($b2bGroupId)
550
    {
551
        $this->b2bGroupId = $b2bGroupId;
552
        return $this;
553
    }
554
555
    /**
556
     * @return null|string
557
     */
558
    public function getComments()
559
    {
560
        return $this->comments;
561
    }
562
563
    /**
564
     * @param null|string $comments
565
     * @return CustomerInterface
566
     */
567
    public function setComments($comments)
568
    {
569
        $this->comments = $comments;
570
        return $this;
571
    }
572
573
    /**
574
     * @return int|null
575
     */
576
    public function getCountryId()
577
    {
578
        return $this->countryId;
579
    }
580
581
    /**
582
     * @param int|null $countryId
583
     * @return CustomerInterface
584
     */
585
    public function setCountryId($countryId)
586
    {
587
        $this->countryId = $countryId;
588
        return $this;
589
    }
590
591
    /**
592
     * @return \DateTimeImmutable|null
593
     */
594
    public function getCreatedDate()
595
    {
596
        return $this->createdDate;
597
    }
598
599
    /**
600
     * @param \DateTimeImmutable|null $createdDate
601
     * @return CustomerInterface
602
     */
603
    public function setCreatedDate($createdDate)
604
    {
605
        $this->createdDate = $createdDate;
606
        return $this;
607
    }
608
609
    /**
610
     * @return null|string
611
     */
612
    public function getCustomerGroupId()
613
    {
614
        return $this->customerGroupId;
615
    }
616
617
    /**
618
     * @param null|string $customerGroupId
619
     * @return CustomerInterface
620
     */
621
    public function setCustomerGroupId($customerGroupId)
622
    {
623
        $this->customerGroupId = $customerGroupId;
624
        return $this;
625
    }
626
627
    /**
628
     * @return null|string
629
     */
630
    public function getCustomerType()
631
    {
632
        return $this->customerType;
633
    }
634
635
    /**
636
     * @param null|string $customerType
637
     * @return CustomerInterface
638
     */
639
    public function setCustomerType($customerType)
640
    {
641
        $this->customerType = $customerType;
642
        return $this;
643
    }
644
645
    /**
646
     * @return bool|null
647
     */
648
    public function getB2b()
649
    {
650
        return $this->b2b;
651
    }
652
653
    /**
654
     * @param bool|null $b2b
655
     * @return CustomerInterface
656
     */
657
    public function setB2b($b2b)
658
    {
659
        $this->b2b = $b2b;
660
        return $this;
661
    }
662
663
    /**
664
     * @return \DateTimeImmutable|null
665
     */
666
    public function getLastLoginDate()
667
    {
668
        return $this->lastLoginDate;
669
    }
670
671
    /**
672
     * @param \DateTimeImmutable|null $lastLoginDate
673
     * @return CustomerInterface
674
     */
675
    public function setLastLoginDate($lastLoginDate)
676
    {
677
        $this->lastLoginDate = $lastLoginDate;
678
        return $this;
679
    }
680
681
    /**
682
     * @return int|null
683
     */
684
    public function getLoginCount()
685
    {
686
        return $this->loginCount;
687
    }
688
689
    /**
690
     * @param int|null $loginCount
691
     * @return CustomerInterface
692
     */
693
    public function setLoginCount($loginCount)
694
    {
695
        $this->loginCount = $loginCount;
696
        return $this;
697
    }
698
699
    /**
700
     * @return null|string
701
     */
702
    public function getPassword()
703
    {
704
        return $this->password;
705
    }
706
707
    /**
708
     * @param null|string $password
709
     * @return CustomerInterface
710
     */
711
    public function setPassword($password)
712
    {
713
        $this->password = $password;
714
        return $this;
715
    }
716
717
    /**
718
     * @return null|string
719
     */
720
    public function getReservedField1()
721
    {
722
        return $this->reservedField1;
723
    }
724
725
    /**
726
     * @param null|string $reservedField1
727
     * @return CustomerInterface
728
     */
729
    public function setReservedField1($reservedField1)
730
    {
731
        $this->reservedField1 = $reservedField1;
732
        return $this;
733
    }
734
735
    /**
736
     * @return null|string
737
     */
738
    public function getReservedField2()
739
    {
740
        return $this->reservedField2;
741
    }
742
743
    /**
744
     * @param null|string $reservedField2
745
     * @return CustomerInterface
746
     */
747
    public function setReservedField2($reservedField2)
748
    {
749
        $this->reservedField2 = $reservedField2;
750
        return $this;
751
    }
752
753
    /**
754
     * @return null|string
755
     */
756
    public function getReservedField3()
757
    {
758
        return $this->reservedField3;
759
    }
760
761
    /**
762
     * @param null|string $reservedField3
763
     * @return CustomerInterface
764
     */
765
    public function setReservedField3($reservedField3)
766
    {
767
        $this->reservedField3 = $reservedField3;
768
        return $this;
769
    }
770
771
    /**
772
     * @return null|string
773
     */
774
    public function getReservedField4()
775
    {
776
        return $this->reservedField4;
777
    }
778
779
    /**
780
     * @param null|string $reservedField4
781
     * @return CustomerInterface
782
     */
783
    public function setReservedField4($reservedField4)
784
    {
785
        $this->reservedField4 = $reservedField4;
786
        return $this;
787
    }
788
789
    /**
790
     * @return null|string
791
     */
792
    public function getReservedField5()
793
    {
794
        return $this->reservedField5;
795
    }
796
797
    /**
798
     * @param null|string $reservedField5
799
     * @return CustomerInterface
800
     */
801
    public function setReservedField5($reservedField5)
802
    {
803
        $this->reservedField5 = $reservedField5;
804
        return $this;
805
    }
806
}
807