B2bCustomer   F
last analyzed

Complexity

Total Complexity 67

Size/Duplication

Total Lines 727
Duplicated Lines 6.74 %

Coupling/Cohesion

Components 5
Dependencies 8

Importance

Changes 0
Metric Value
wmc 67
lcom 5
cbo 8
dl 49
loc 727
rs 1.8461
c 0
b 0
f 0

47 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A getId() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
A getLifetime() 0 4 1
A setLifetime() 0 4 1
A getShippingAddress() 0 4 1
A setShippingAddress() 0 4 1
A getBillingAddress() 0 4 1
A setBillingAddress() 0 4 1
A getAccount() 0 4 1
A setAccount() 0 4 1
A getContact() 0 4 1
A setContact() 0 4 1
A getLeads() 0 4 1
A setLeads() 0 4 1
A addLead() 0 7 2
A removeLead() 0 7 2
A getOpportunities() 0 4 1
A setOpportunities() 0 4 1
A addOpportunity() 0 7 2
A removeOpportunity() 0 7 2
A getOwner() 0 4 1
A setOwner() 0 4 1
A getCreatedAt() 0 4 1
A setCreatedAt() 0 4 1
A getUpdatedAt() 0 4 1
A setUpdatedAt() 0 4 1
A prePersist() 0 4 1
A preUpdate() 0 4 1
A __toString() 0 4 1
A setOrganization() 0 6 1
A getOrganization() 0 4 1
A resetPhones() 0 8 2
A addPhone() 8 8 2
A removePhone() 0 7 2
A getPhones() 0 4 1
A hasPhone() 0 4 1
A getPrimaryPhone() 0 11 3
A setPrimaryPhone() 12 12 4
A resetEmails() 0 8 2
A addEmail() 8 8 2
A removeEmail() 0 7 2
A getEmails() 0 4 1
A hasEmail() 0 4 1
A getPrimaryEmail() 0 11 3
A setPrimaryEmail() 12 12 4

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 B2bCustomer 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

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 B2bCustomer, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Oro\Bundle\SalesBundle\Entity;
4
5
use Doctrine\Common\Collections\Collection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Doctrine\Common\Collections\ArrayCollection;
8
9
use Oro\Bundle\AddressBundle\Entity\Address;
10
use Oro\Bundle\EmailBundle\Entity\EmailOwnerInterface;
11
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
12
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
13
use Oro\Bundle\OrganizationBundle\Entity\Organization;
14
use Oro\Bundle\UserBundle\Entity\User;
15
use Oro\Bundle\AccountBundle\Entity\Account;
16
use Oro\Bundle\ContactBundle\Entity\Contact;
17
use Oro\Bundle\SalesBundle\Model\ExtendB2bCustomer;
18
use Oro\Bundle\ChannelBundle\Model\ChannelEntityTrait;
19
use Oro\Bundle\ChannelBundle\Model\ChannelAwareInterface;
20
use Oro\Bundle\ChannelBundle\Model\CustomerIdentityInterface;
21
22
/**
23
 * @ORM\Entity(repositoryClass="Oro\Bundle\SalesBundle\Entity\Repository\B2bCustomerRepository")
24
 * @ORM\Table(name="orocrm_sales_b2bcustomer")
25
 * @ORM\HasLifecycleCallbacks()
26
 * @Config(
27
 *      routeName="oro_sales_b2bcustomer_index",
28
 *      routeView="oro_sales_b2bcustomer_view",
29
 *      defaultValues={
30
 *          "entity"={
31
 *              "icon"="icon-user-md",
32
 *              "contact_information"={
33
 *                  "email"={
34
 *                      {"fieldName"="primaryEmail"}
35
 *                  },
36
 *                  "phone"={
37
 *                      {"fieldName"="primaryPhone"}
38
 *                  }
39
 *              }
40
 *          },
41
 *          "ownership"={
42
 *              "owner_type"="USER",
43
 *              "owner_field_name"="owner",
44
 *              "owner_column_name"="user_owner_id",
45
 *              "organization_field_name"="organization",
46
 *              "organization_column_name"="organization_id"
47
 *          },
48
 *          "security"={
49
 *              "type"="ACL",
50
 *              "group_name"="",
51
 *              "category"="sales_data"
52
 *          },
53
 *          "dataaudit"={
54
 *              "auditable"=true
55
 *          },
56
 *          "form"={
57
 *              "form_type"="oro_sales_b2bcustomer_select"
58
 *          },
59
 *          "grid"={
60
 *              "default"="orocrm-sales-b2bcustomers-grid",
61
 *              "context"="orocrm-sales-b2bcustomers-for-context-grid"
62
 *          },
63
 *         "tag"={
64
 *              "enabled"=true
65
 *          }
66
 *      }
67
 * )
68
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
69
 * @SuppressWarnings(PHPMD.ExcessivePublicCount)
70
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
71
 */
72
class B2bCustomer extends ExtendB2bCustomer implements
73
    ChannelAwareInterface,
74
    CustomerIdentityInterface
75
{
76
    use ChannelEntityTrait;
77
78
    /**
79
     * @var integer
80
     *
81
     * @ORM\Column(name="id", type="integer")
82
     * @ORM\Id
83
     * @ORM\GeneratedValue(strategy="AUTO")
84
     * @ConfigField(
85
     *  defaultValues={
86
     *      "importexport"={
87
     *          "order"=0
88
     *      }
89
     *  }
90
     * )
91
     */
92
    protected $id;
93
94
    /**
95
     * @var string
96
     *
97
     * @ORM\Column(type="string", length=255)
98
     * @ConfigField(
99
     *      defaultValues={
100
     *          "dataaudit"={
101
     *              "auditable"=true
102
     *          },
103
     *          "importexport"={
104
     *              "identity"=true,
105
     *              "order"=10
106
     *          }
107
     *      }
108
     * )
109
     */
110
    protected $name;
111
112
    /**
113
     * @var double
114
     *
115
     * @ORM\Column(name="lifetime", type="money", nullable=true)
116
     * @ConfigField(
117
     *      defaultValues={
118
     *          "dataaudit"={
119
     *              "auditable"=true
120
     *          },
121
     *          "importexport"={
122
     *              "full"=true,
123
     *              "order"=15
124
     *          }
125
     *      }
126
     * )
127
     */
128
    protected $lifetime = 0;
129
130
    /**
131
     * @var Address $shippingAddress
132
     *
133
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\AddressBundle\Entity\Address", cascade={"persist", "remove"})
134
     * @ORM\JoinColumn(name="shipping_address_id", referencedColumnName="id", onDelete="SET NULL")
135
     * @ConfigField(
136
     *      defaultValues={
137
     *          "importexport"={
138
     *              "full"=true,
139
     *              "order"=20
140
     *          }
141
     *      }
142
     * )
143
     */
144
    protected $shippingAddress;
145
146
    /**
147
     * @var Address $billingAddress
148
     *
149
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\AddressBundle\Entity\Address", cascade={"persist", "remove"})
150
     * @ORM\JoinColumn(name="billing_address_id", referencedColumnName="id", onDelete="SET NULL")
151
     * @ConfigField(
152
     *      defaultValues={
153
     *          "importexport"={
154
     *              "full"=true,
155
     *              "order"=30
156
     *          }
157
     *      }
158
     * )
159
     */
160
    protected $billingAddress;
161
162
    /**
163
     * @var Account
164
     *
165
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\AccountBundle\Entity\Account", cascade="persist")
166
     * @ORM\JoinColumn(name="account_id", referencedColumnName="id", onDelete="SET NULL")
167
     * @ConfigField(
168
     *  defaultValues={
169
     *      "dataaudit"={"auditable"=true},
170
     *      "importexport"={
171
     *          "order"=40,
172
     *          "short"=true
173
     *      }
174
     *  }
175
     * )
176
     */
177
    protected $account;
178
179
    /**
180
     * @var Contact
181
     *
182
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\ContactBundle\Entity\Contact")
183
     * @ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="SET NULL")
184
     * @ConfigField(
185
     *  defaultValues={
186
     *      "dataaudit"={"auditable"=true},
187
     *      "importexport"={
188
     *          "order"=50,
189
     *          "short"=true
190
     *      }
191
     *  }
192
     * )
193
     */
194
    protected $contact;
195
196
    /**
197
     * @var ArrayCollection
198
     *
199
     * @ORM\OneToMany(targetEntity="Oro\Bundle\SalesBundle\Entity\Lead", mappedBy="customer", cascade={"remove"})
200
     */
201
    protected $leads;
202
203
    /**
204
     * @var ArrayCollection
205
     *
206
     * @ORM\OneToMany(
207
     *     targetEntity="Oro\Bundle\SalesBundle\Entity\Opportunity",
208
     *     mappedBy="customer",
209
     *     cascade={"remove"}
210
     * )
211
     */
212
    protected $opportunities;
213
214
    /**
215
     * @var User
216
     *
217
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
218
     * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL")
219
     * @ConfigField(
220
     *  defaultValues={
221
     *      "dataaudit"={"auditable"=true},
222
     *      "importexport"={
223
     *          "order"=70,
224
     *          "short"=true
225
     *      }
226
     *  }
227
     * )
228
     */
229
    protected $owner;
230
231
    /**
232
     * @var Organization
233
     *
234
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization")
235
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
236
     */
237
    protected $organization;
238
239
    /**
240
     * @var \DateTime $created
241
     *
242
     * @ORM\Column(type="datetime")
243
     * @ConfigField(
244
     *      defaultValues={
245
     *          "entity"={
246
     *              "label"="oro.ui.created_at"
247
     *          },
248
     *          "importexport"={
249
     *              "excluded"=true
250
     *          }
251
     *      }
252
     * )
253
     */
254
    protected $createdAt;
255
256
    /**
257
     * @var \DateTime $updated
258
     *
259
     * @ORM\Column(type="datetime")
260
     * @ConfigField(
261
     *      defaultValues={
262
     *          "entity"={
263
     *              "label"="oro.ui.updated_at"
264
     *          },
265
     *          "importexport"={
266
     *              "excluded"=true
267
     *          }
268
     *      }
269
     * )
270
     */
271
    protected $updatedAt;
272
273
    /**
274
     * @var Collection
275
     *
276
     * @ORM\OneToMany(targetEntity="Oro\Bundle\SalesBundle\Entity\B2bCustomerPhone", mappedBy="owner",
277
     *    mappedBy="owner", cascade={"all"}, orphanRemoval=true
278
     * ))
279
     * @ORM\OrderBy({"primary" = "DESC"})
280
     * @ConfigField(
281
     *      defaultValues={
282
     *          "importexport"={
283
     *              "order"=80
284
     *          },
285
     *          "dataaudit"={
286
     *              "auditable"=true
287
     *          }
288
     *      }
289
     * )
290
     */
291
    protected $phones;
292
293
    /**
294
     * @var Collection
295
     *
296
     * @ORM\OneToMany(targetEntity="Oro\Bundle\SalesBundle\Entity\B2bCustomerEmail",
297
     *    mappedBy="owner", cascade={"all"}, orphanRemoval=true
298
     * )
299
     * @ORM\OrderBy({"primary" = "DESC"})
300
     * @ConfigField(
301
     *      defaultValues={
302
     *          "importexport"={
303
     *              "order"=90
304
     *          },
305
     *          "dataaudit"={
306
     *              "auditable"=true
307
     *          }
308
     *      }
309
     * )
310
     */
311
    protected $emails;
312
313 View Code Duplication
    public function __construct()
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...
314
    {
315
        parent::__construct();
316
317
        $this->leads         = new ArrayCollection();
318
        $this->opportunities = new ArrayCollection();
319
        $this->phones        = new ArrayCollection();
320
        $this->emails        = new ArrayCollection();
321
    }
322
323
    /**
324
     * @return int
325
     */
326
    public function getId()
327
    {
328
        return $this->id;
329
    }
330
331
    /**
332
     * @return string
333
     */
334
    public function getName()
335
    {
336
        return $this->name;
337
    }
338
339
    /**
340
     * @param string $name
341
     */
342
    public function setName($name)
343
    {
344
        $this->name = $name;
345
    }
346
347
    /**
348
     * @return float
349
     */
350
    public function getLifetime()
351
    {
352
        return $this->lifetime;
353
    }
354
355
    /**
356
     * @param float $lifetime
357
     */
358
    public function setLifetime($lifetime)
359
    {
360
        $this->lifetime = $lifetime;
361
    }
362
363
    /**
364
     * @return Address
365
     */
366
    public function getShippingAddress()
367
    {
368
        return $this->shippingAddress;
369
    }
370
371
    /**
372
     * @param Address|null $shippingAddress
373
     */
374
    public function setShippingAddress(Address $shippingAddress = null)
375
    {
376
        $this->shippingAddress = $shippingAddress;
377
    }
378
379
    /**
380
     * @return Address
381
     */
382
    public function getBillingAddress()
383
    {
384
        return $this->billingAddress;
385
    }
386
387
    /**
388
     * @param Address|null $billingAddress
389
     */
390
    public function setBillingAddress(Address $billingAddress = null)
391
    {
392
        $this->billingAddress = $billingAddress;
393
    }
394
395
    /**
396
     * @return Account
397
     */
398
    public function getAccount()
399
    {
400
        return $this->account;
401
    }
402
403
    /**
404
     * @param Account|null $account
405
     */
406
    public function setAccount(Account $account = null)
407
    {
408
        $this->account = $account;
409
    }
410
411
    /**
412
     * @return Contact
413
     */
414
    public function getContact()
415
    {
416
        return $this->contact;
417
    }
418
419
    /**
420
     * @param Contact|null $contact
421
     */
422
    public function setContact(Contact $contact = null)
423
    {
424
        $this->contact = $contact;
425
    }
426
427
    /**
428
     * @return ArrayCollection
429
     */
430
    public function getLeads()
431
    {
432
        return $this->leads;
433
    }
434
435
    /**
436
     * @param ArrayCollection $leads
437
     */
438
    public function setLeads(ArrayCollection $leads)
439
    {
440
        $this->leads = $leads;
441
    }
442
443
    /**
444
     * @param Lead $lead
445
     */
446
    public function addLead(Lead $lead)
447
    {
448
        if (!$this->getLeads()->contains($lead)) {
449
            $this->getLeads()->add($lead);
450
            $lead->setCustomer($this);
451
        }
452
    }
453
454
    /**
455
     * @param Lead $lead
456
     */
457
    public function removeLead(Lead $lead)
458
    {
459
        if ($this->getLeads()->contains($lead)) {
460
            $this->getLeads()->removeElement($lead);
461
            $lead->removeCustomer();
462
        }
463
    }
464
465
    /**
466
     * @return ArrayCollection
467
     */
468
    public function getOpportunities()
469
    {
470
        return $this->opportunities;
471
    }
472
473
    /**
474
     * @param ArrayCollection $opportunities
475
     */
476
    public function setOpportunities(ArrayCollection $opportunities)
477
    {
478
        $this->opportunities = $opportunities;
479
    }
480
481
    /**
482
     * @param Opportunity $opportunity
483
     */
484
    public function addOpportunity(Opportunity $opportunity)
485
    {
486
        if (!$this->getOpportunities()->contains($opportunity)) {
487
            $this->getOpportunities()->add($opportunity);
488
            $opportunity->setCustomer($this);
489
        }
490
    }
491
492
    /**
493
     * @param Opportunity $opportunity
494
     */
495
    public function removeOpportunity(Opportunity $opportunity)
496
    {
497
        if ($this->getOpportunities()->contains($opportunity)) {
498
            $this->getOpportunities()->removeElement($opportunity);
499
            $opportunity->removeCustomer();
500
        }
501
    }
502
503
    /**
504
     * @return mixed
505
     */
506
    public function getOwner()
507
    {
508
        return $this->owner;
509
    }
510
511
    /**
512
     * @param User $owner
513
     */
514
    public function setOwner(User $owner = null)
515
    {
516
        $this->owner = $owner;
517
    }
518
519
    /**
520
     * @return \DateTime
521
     */
522
    public function getCreatedAt()
523
    {
524
        return $this->createdAt;
525
    }
526
527
    /**
528
     * @param \DateTime|null $createdAt
529
     */
530
    public function setCreatedAt(\DateTime $createdAt = null)
531
    {
532
        $this->createdAt = $createdAt;
533
    }
534
535
    /**
536
     * @return \DateTime
537
     */
538
    public function getUpdatedAt()
539
    {
540
        return $this->updatedAt;
541
    }
542
543
    /**
544
     * @param \DateTime|null $updatedAt
545
     */
546
    public function setUpdatedAt(\DateTime $updatedAt = null)
547
    {
548
        $this->updatedAt = $updatedAt;
549
    }
550
551
    /**
552
     * Pre persist event listener
553
     *
554
     * @ORM\PrePersist
555
     */
556
    public function prePersist()
557
    {
558
        $this->createdAt = $this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
559
    }
560
561
    /**
562
     * Pre update event handler
563
     *
564
     * @ORM\PreUpdate
565
     */
566
    public function preUpdate()
567
    {
568
        $this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
569
    }
570
571
    /**
572
     * @return string
573
     */
574
    public function __toString()
575
    {
576
        return (string) $this->getName();
577
    }
578
579
    /**
580
     * Set organization
581
     *
582
     * @param Organization $organization
583
     * @return B2bCustomer
584
     */
585
    public function setOrganization(Organization $organization = null)
586
    {
587
        $this->organization = $organization;
588
589
        return $this;
590
    }
591
592
    /**
593
     * Get organization
594
     *
595
     * @return Organization
596
     */
597
    public function getOrganization()
598
    {
599
        return $this->organization;
600
    }
601
602
    /**
603
     * Set phones.
604
     *
605
     * This method could not be named setPhones because of bug CRM-253.
606
     *
607
     * @param Collection|B2bCustomerPhone[] $phones
608
     *
609
     * @return B2bCustomer
610
     */
611
    public function resetPhones($phones)
612
    {
613
        $this->phones->clear();
614
        foreach ($phones as $phone) {
615
            $this->addPhone($phone);
616
        }
617
        return $this;
618
    }
619
    /**
620
     * Add phone
621
     *
622
     * @param B2bCustomerPhone $phone
623
     *
624
     * @return B2bCustomer
625
     */
626 View Code Duplication
    public function addPhone(B2bCustomerPhone $phone)
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...
627
    {
628
        if (!$this->phones->contains($phone)) {
629
            $this->phones->add($phone);
630
            $phone->setOwner($this);
631
        }
632
        return $this;
633
    }
634
    /**
635
     * Remove phone
636
     *
637
     * @param B2bCustomerPhone $phone
638
     *
639
     * @return B2bCustomer
640
     */
641
    public function removePhone(B2bCustomerPhone $phone)
642
    {
643
        if ($this->phones->contains($phone)) {
644
            $this->phones->removeElement($phone);
645
        }
646
        return $this;
647
    }
648
    /**
649
     * Get phones
650
     *
651
     * @return Collection|B2bCustomerPhone[]
652
     */
653
    public function getPhones()
654
    {
655
        return $this->phones;
656
    }
657
    /**
658
     * @param B2bCustomerPhone $phone
659
     *
660
     * @return bool
661
     */
662
    public function hasPhone(B2bCustomerPhone $phone)
663
    {
664
        return $this->getPhones()->contains($phone);
665
    }
666
    /**
667
     * Gets primary phone if it's available.
668
     *
669
     * @return B2bCustomerPhone|null
670
     */
671
    public function getPrimaryPhone()
672
    {
673
        $result = null;
674
        foreach ($this->getPhones() as $phone) {
675
            if ($phone->isPrimary()) {
676
                $result = $phone;
677
                break;
678
            }
679
        }
680
        return $result;
681
    }
682
    /**
683
     * @param B2bCustomerPhone $phone
684
     *
685
     * @return B2bCustomer
686
     */
687 View Code Duplication
    public function setPrimaryPhone(B2bCustomerPhone $phone)
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...
688
    {
689
        if ($this->hasPhone($phone)) {
690
            $phone->setPrimary(true);
691
            foreach ($this->getPhones() as $otherPhone) {
692
                if (!$phone->isEqual($otherPhone)) {
693
                    $otherPhone->setPrimary(false);
694
                }
695
            }
696
        }
697
        return $this;
698
    }
699
700
    /**
701
     * Set emails.
702
     *
703
     * This method could not be named setEmails because of bug CRM-253.
704
     *
705
     * @param Collection|B2bCustomerEmail[] $emails
706
     *
707
     * @return B2bCustomer
708
     */
709
    public function resetEmails($emails)
710
    {
711
        $this->emails->clear();
712
        foreach ($emails as $email) {
713
            $this->addEmail($email);
714
        }
715
        return $this;
716
    }
717
    /**
718
     * Add email
719
     *
720
     * @param B2bCustomerEmail $email
721
     *
722
     * @return B2bCustomer
723
     */
724 View Code Duplication
    public function addEmail(B2bCustomerEmail $email)
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...
725
    {
726
        if (!$this->emails->contains($email)) {
727
            $this->emails->add($email);
728
            $email->setOwner($this);
729
        }
730
        return $this;
731
    }
732
    /**
733
     * Remove email
734
     *
735
     * @param B2bCustomerEmail $email
736
     *
737
     * @return B2bCustomer
738
     */
739
    public function removeEmail(B2bCustomerEmail $email)
740
    {
741
        if ($this->emails->contains($email)) {
742
            $this->emails->removeElement($email);
743
        }
744
        return $this;
745
    }
746
    /**
747
     * Get emails
748
     *
749
     * @return Collection|B2bCustomerEmail[]
750
     */
751
    public function getEmails()
752
    {
753
        return $this->emails;
754
    }
755
    /**
756
     * @param B2bCustomerEmail $email
757
     *
758
     * @return bool
759
     */
760
    public function hasEmail(B2bCustomerEmail $email)
761
    {
762
        return $this->getEmails()->contains($email);
763
    }
764
    /**
765
     * Gets primary email if it's available.
766
     *
767
     * @return B2bCustomerEmail|null
768
     */
769
    public function getPrimaryEmail()
770
    {
771
        $result = null;
772
        foreach ($this->getEmails() as $email) {
773
            if ($email->isPrimary()) {
774
                $result = $email;
775
                break;
776
            }
777
        }
778
        return $result;
779
    }
780
781
    /**
782
     * @param B2bCustomerEmail $email
783
     *
784
     * @return B2bCustomer
785
     */
786 View Code Duplication
    public function setPrimaryEmail(B2bCustomerEmail $email)
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...
787
    {
788
        if ($this->hasEmail($email)) {
789
            $email->setPrimary(true);
790
            foreach ($this->getEmails() as $otherEmail) {
791
                if (!$email->isEqual($otherEmail)) {
792
                    $otherEmail->setPrimary(false);
793
                }
794
            }
795
        }
796
        return $this;
797
    }
798
}
799