Completed
Push — master ( 664fb1...60ffba )
by
unknown
26:32
created

Lead   F

Complexity

Total Complexity 94

Size/Duplication

Total Lines 1277
Duplicated Lines 9.55 %

Coupling/Cohesion

Components 7
Dependencies 8

Importance

Changes 0
Metric Value
wmc 94
lcom 7
cbo 8
dl 122
loc 1277
rs 0.6314
c 0
b 0
f 0

71 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A getId() 0 4 1
A setName() 0 6 1
A getName() 0 4 1
A setNamePrefix() 0 6 1
A getNamePrefix() 0 4 1
A setFirstName() 0 6 1
A getFirstName() 0 4 1
A getMiddleName() 0 4 1
A setMiddleName() 0 6 1
A setLastName() 0 6 1
A getLastName() 0 4 1
A setNameSuffix() 0 6 1
A getNameSuffix() 0 4 1
A setJobTitle() 0 6 1
A getJobTitle() 0 4 1
A setCompanyName() 0 6 1
A getCompanyName() 0 4 1
A setWebsite() 0 6 1
A getWebsite() 0 4 1
A setNumberOfEmployees() 0 6 1
A getNumberOfEmployees() 0 4 1
A setIndustry() 0 6 1
A getIndustry() 0 4 1
A addAddress() 10 10 2
A getPrimaryAddress() 14 14 3
A setPrimaryAddress() 14 14 4
A getAddresses() 0 4 1
A containsAddress() 0 4 1
A removeAddress() 0 8 2
A hasAddress() 0 4 1
A setAddress() 0 4 1
A setContact() 0 6 1
A getContact() 0 4 1
A getCreatedAt() 0 4 1
A setCreatedAt() 0 6 1
A getUpdatedAt() 0 4 1
A setUpdatedAt() 0 6 1
A __toString() 0 4 1
A beforeSave() 0 4 1
A beforeUpdate() 0 4 1
A getOwner() 0 4 1
A setOwner() 0 6 1
A getOpportunities() 0 4 1
A addOpportunity() 9 9 2
A removeOpportunity() 9 9 2
A getNotes() 0 4 1
A setNotes() 0 6 1
A setCustomer() 0 4 1
A getCustomer() 0 4 1
A setOrganization() 0 6 1
A getOrganization() 0 4 1
A removeCustomer() 0 6 1
A resetPhones() 0 10 2
A addPhone() 9 9 2
A removePhone() 0 8 2
A getPhones() 0 4 1
A hasPhone() 0 4 1
A getPrimaryPhone() 13 13 3
A setPrimaryPhone() 13 13 4
A resetEmails() 0 10 2
A addEmail() 9 9 2
A removeEmail() 0 8 2
A getEmails() 0 4 1
A getEmail() 0 9 2
A hasEmail() 0 4 1
A getPrimaryEmail() 13 13 3
A getTwitter() 0 4 1
A setTwitter() 0 4 1
A getLinkedIn() 0 4 1
A setLinkedIn() 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 Lead 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 Lead, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Oro\Bundle\SalesBundle\Entity;
4
5
use Doctrine\ORM\Event\LifecycleEventArgs;
6
use Doctrine\ORM\Mapping as ORM;
7
use Doctrine\Common\Collections\Collection;
8
use Doctrine\Common\Collections\ArrayCollection;
9
10
use Oro\Bundle\AddressBundle\Entity\AbstractAddress;
11
use Oro\Bundle\EmailBundle\Entity\EmailOwnerInterface;
12
use Oro\Bundle\EmailBundle\Model\EmailHolderInterface;
13
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
14
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
15
use Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper;
16
use Oro\Bundle\OrganizationBundle\Entity\Organization;
17
use Oro\Bundle\UserBundle\Entity\User;
18
use Oro\Bundle\LocaleBundle\Model\FullNameInterface;
19
use Oro\Bundle\ContactBundle\Entity\Contact;
20
use Oro\Bundle\SalesBundle\Model\ExtendLead;
21
use Oro\Bundle\ChannelBundle\Model\ChannelEntityTrait;
22
use Oro\Bundle\ChannelBundle\Model\ChannelAwareInterface;
23
24
/**
25
 * @SuppressWarnings(PHPMD.ExcessivePublicCount)
26
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
27
 * @SuppressWarnings(PHPMD.TooManyFields)
28
 *
29
 * @ORM\Table(
30
 *      name="orocrm_sales_lead",
31
 *      indexes={@ORM\Index(name="lead_created_idx",columns={"createdAt"})}
32
 * )
33
 * @ORM\Entity(repositoryClass="Oro\Bundle\SalesBundle\Entity\Repository\LeadRepository")
34
 * @ORM\HasLifecycleCallbacks()
35
 * @Config(
36
 *      routeName="oro_sales_lead_index",
37
 *      routeView="oro_sales_lead_view",
38
 *      defaultValues={
39
 *          "entity"={
40
 *              "icon"="icon-phone",
41
 *              "contact_information"={
42
 *                  "email"={
43
 *                      {"fieldName"="primaryEmail"}
44
 *                  },
45
 *                  "phone"={
46
 *                      {"fieldName"="primaryPhone"}
47
 *                  }
48
 *              }
49
 *          },
50
 *          "ownership"={
51
 *              "owner_type"="USER",
52
 *              "owner_field_name"="owner",
53
 *              "owner_column_name"="user_owner_id",
54
 *              "organization_field_name"="organization",
55
 *              "organization_column_name"="organization_id"
56
 *          },
57
 *          "security"={
58
 *              "type"="ACL",
59
 *              "group_name"="",
60
 *              "category"="sales_data"
61
 *          },
62
 *          "form"={
63
 *              "form_type"="oro_sales_lead_select",
64
 *              "grid_name"="sales-lead-grid",
65
 *          },
66
 *          "dataaudit"={
67
 *              "auditable"=true
68
 *          },
69
 *          "grid"={
70
 *              "default"="sales-lead-grid",
71
 *              "context"="sales-lead-for-context-grid"
72
 *          },
73
 *          "tag"={
74
 *              "enabled"=true
75
 *          }
76
 *      }
77
 * )
78
 *
79
 * @SuppressWarnings(PHPMD.ExcessiveClassLength)
80
 */
81
class Lead extends ExtendLead implements
82
    FullNameInterface,
83
    EmailHolderInterface,
84
    ChannelAwareInterface
85
{
86
    use ChannelEntityTrait;
87
88
    const INTERNAL_STATUS_CODE = 'lead_status';
89
90
    /**
91
     * @var integer
92
     *
93
     * @ORM\Column(name="id", type="integer")
94
     * @ORM\Id
95
     * @ORM\GeneratedValue(strategy="AUTO")
96
     * @ConfigField(
97
     *  defaultValues={
98
     *      "importexport"={
99
     *          "order"=0
100
     *      }
101
     *  }
102
     * )
103
     */
104
    protected $id;
105
106
    /**
107
     * @var Contact
108
     *
109
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\ContactBundle\Entity\Contact")
110
     * @ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="SET NULL")
111
     * @ConfigField(
112
     *  defaultValues={
113
     *      "dataaudit"={"auditable"=true},
114
     *      "importexport"={
115
     *          "order"=150,
116
     *          "short"=true
117
     *      }
118
     *  }
119
     * )
120
     */
121
    protected $contact;
122
123
    /**
124
     * @var string
125
     *
126
     * @ORM\Column(name="name", type="string", length=255)
127
     * @ConfigField(
128
     *  defaultValues={
129
     *      "dataaudit"={"auditable"=true},
130
     *      "importexport"={
131
     *          "order"=20,
132
     *          "identity"=true
133
     *      }
134
     *  }
135
     * )
136
     */
137
    protected $name;
138
139
    /**
140
     * @var string
141
     *
142
     * @ORM\Column(name="name_prefix", type="string", length=255, nullable=true)
143
     * @ConfigField(
144
     *  defaultValues={
145
     *      "dataaudit"={"auditable"=true},
146
     *      "importexport"={
147
     *          "order"=30
148
     *      }
149
     *  }
150
     * )
151
     */
152
    protected $namePrefix;
153
154
    /**
155
     * @var string
156
     *
157
     * @ORM\Column(name="first_name", type="string", length=255, nullable=true)
158
     * @ConfigField(
159
     *  defaultValues={
160
     *      "dataaudit"={"auditable"=true},
161
     *      "importexport"={
162
     *          "order"=40
163
     *      }
164
     *  }
165
     * )
166
     */
167
    protected $firstName;
168
169
    /**
170
     * @var string
171
     *
172
     * @ORM\Column(name="middle_name", type="string", length=255, nullable=true)
173
     * @ConfigField(
174
     *  defaultValues={
175
     *      "dataaudit"={"auditable"=true},
176
     *      "importexport"={
177
     *          "order"=50
178
     *      }
179
     *  }
180
     * )
181
     */
182
    protected $middleName;
183
184
    /**
185
     * @var string
186
     *
187
     * @ORM\Column(name="last_name", type="string", length=255, nullable=true)
188
     * @ConfigField(
189
     *  defaultValues={
190
     *      "dataaudit"={"auditable"=true},
191
     *      "importexport"={
192
     *          "order"=60
193
     *      }
194
     *  }
195
     * )
196
     */
197
    protected $lastName;
198
199
    /**
200
     * @var string
201
     *
202
     * @ORM\Column(name="name_suffix", type="string", length=255, nullable=true)
203
     * @ConfigField(
204
     *  defaultValues={
205
     *      "dataaudit"={"auditable"=true},
206
     *      "importexport"={
207
     *          "order"=70
208
     *      }
209
     *  }
210
     * )
211
     */
212
    protected $nameSuffix;
213
214
    /**
215
     * @var string
216
     *
217
     * @ORM\Column(name="job_title", type="string", length=255, nullable=true)
218
     * @ConfigField(
219
     *  defaultValues={
220
     *      "dataaudit"={"auditable"=true},
221
     *      "importexport"={
222
     *          "order"=80
223
     *      }
224
     *  }
225
     * )
226
     */
227
    protected $jobTitle;
228
    
229
    /**
230
     * @var Collection
231
     *
232
     * @ORM\OneToMany(targetEntity="Oro\Bundle\SalesBundle\Entity\LeadPhone", mappedBy="owner",
233
     *    mappedBy="owner", cascade={"all"}, orphanRemoval=true
234
     * ))
235
     * @ORM\OrderBy({"primary" = "DESC"})
236
     * @ConfigField(
237
     *      defaultValues={
238
     *          "importexport"={
239
     *              "order"=220
240
     *          },
241
     *          "dataaudit"={
242
     *              "auditable"=true
243
     *          }
244
     *      }
245
     * )
246
     */
247
    protected $phones;
248
249
    /**
250
     * @var Collection
251
     *
252
     * @ORM\OneToMany(targetEntity="Oro\Bundle\SalesBundle\Entity\LeadEmail",
253
     *    mappedBy="owner", cascade={"all"}, orphanRemoval=true
254
     * )
255
     * @ORM\OrderBy({"primary" = "DESC"})
256
     * @ConfigField(
257
     *      defaultValues={
258
     *          "importexport"={
259
     *              "order"=210
260
     *          },
261
     *          "dataaudit"={
262
     *              "auditable"=true
263
     *          }
264
     *      }
265
     * )
266
     */
267
    protected $emails;
268
269
    /**
270
     * @var string
271
     *
272
     * @ORM\Column(name="company_name", type="string", length=255, nullable=true)
273
     * @ConfigField(
274
     *  defaultValues={
275
     *      "dataaudit"={"auditable"=true},
276
     *      "importexport"={
277
     *          "order"=110
278
     *      }
279
     *  }
280
     * )
281
     */
282
    protected $companyName;
283
284
    /**
285
     * @var string
286
     *
287
     * @ORM\Column(name="website", type="string", length=255, nullable=true)
288
     * @ConfigField(
289
     *  defaultValues={
290
     *      "dataaudit"={"auditable"=true},
291
     *      "importexport"={
292
     *          "order"=120
293
     *      }
294
     *  }
295
     * )
296
     */
297
    protected $website;
298
299
    /**
300
     * @var integer
301
     *
302
     * @ORM\Column(name="number_of_employees", type="integer", nullable=true)
303
     * @ConfigField(
304
     *  defaultValues={
305
     *      "dataaudit"={"auditable"=true},
306
     *      "importexport"={
307
     *          "order"=130
308
     *      }
309
     *  }
310
     * )
311
     */
312
    protected $numberOfEmployees;
313
314
    /**
315
     * @var string
316
     *
317
     * @ORM\Column(name="industry", type="string", length=255, nullable=true)
318
     * @ConfigField(
319
     *  defaultValues={
320
     *      "dataaudit"={"auditable"=true},
321
     *      "importexport"={
322
     *          "order"=140
323
     *      }
324
     *  }
325
     * )
326
     */
327
    protected $industry;
328
329
    /**
330
     * @deprecated since 1.10. Use $addresses collection field instead
331
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\AddressBundle\Entity\Address", cascade={"persist", "remove"})
332
     * @ORM\JoinColumn(name="address_id", referencedColumnName="id", onDelete="SET NULL", nullable=true)
333
     * @ConfigField(
334
     *      defaultValues={
335
     *          "importexport"={
336
     *              "excluded"=true
337
     *          }
338
     *      }
339
     * )
340
     */
341
    protected $address;
342
343
    /**
344
     * @var Collection
345
     *
346
     * @ORM\OneToMany(targetEntity="Oro\Bundle\SalesBundle\Entity\LeadAddress",
347
     *    mappedBy="owner", cascade={"all"}, orphanRemoval=true
348
     * )
349
     * @ORM\OrderBy({"primary" = "DESC"})
350
     * @ConfigField(
351
     *      defaultValues={
352
     *          "importexport"={
353
     *              "full"=true,
354
     *              "order"=170
355
     *          },
356
     *          "dataaudit"={
357
     *              "auditable"=true
358
     *          }
359
     *      }
360
     * )
361
     */
362
    protected $addresses;
363
364
    /**
365
     * @var \DateTime
366
     *
367
     * @ORM\Column(type="datetime")
368
     * @ConfigField(
369
     *      defaultValues={
370
     *          "entity"={
371
     *              "label"="oro.ui.created_at"
372
     *          },
373
     *          "importexport"={
374
     *              "excluded"=true
375
     *          }
376
     *      }
377
     * )
378
     */
379
    protected $createdAt;
380
381
    /**
382
     * @var \DateTime
383
     *
384
     * @ORM\Column(type="datetime", nullable=true)
385
     * @ConfigField(
386
     *      defaultValues={
387
     *          "entity"={
388
     *              "label"="oro.ui.updated_at"
389
     *          },
390
     *          "importexport"={
391
     *              "excluded"=true
392
     *          }
393
     *      }
394
     * )
395
     */
396
    protected $updatedAt;
397
398
    /**
399
     * @var User
400
     *
401
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
402
     * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL")
403
     * @ConfigField(
404
     *  defaultValues={
405
     *      "dataaudit"={"auditable"=true},
406
     *      "importexport"={
407
     *          "order"=180,
408
     *          "short"=true
409
     *      }
410
     *  }
411
     * )
412
     */
413
    protected $owner;
414
415
    /**
416
     * @var ArrayCollection
417
     *
418
     * @ORM\OneToMany(targetEntity="Oro\Bundle\SalesBundle\Entity\Opportunity", mappedBy="lead")
419
     * @ConfigField(
420
     *  defaultValues={
421
     *      "importexport"={
422
     *          "order"=190,
423
     *          "short"=true
424
     *      }
425
     *  }
426
     * )
427
     */
428
    protected $opportunities;
429
430
    /**
431
     * @var string
432
     *
433
     * @ORM\Column(name="notes", type="text", nullable=true)
434
     * @ConfigField(
435
     *  defaultValues={
436
     *      "dataaudit"={"auditable"=true},
437
     *      "importexport"={
438
     *          "order"=140
439
     *      }
440
     *  }
441
     * )
442
     */
443
    protected $notes;
444
445
    /**
446
     * @var Organization
447
     *
448
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization")
449
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
450
     */
451
    protected $organization;
452
453
    /**
454
     * @var B2bCustomer
455
     *
456
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\SalesBundle\Entity\B2bCustomer", inversedBy="leads")
457
     * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="SET NULL")
458
     * @ConfigField(
459
     *  defaultValues={
460
     *      "dataaudit"={"auditable"=true},
461
     *      "importexport"={
462
     *          "order"=160,
463
     *          "short"=true
464
     *      }
465
     *  }
466
     * )
467
     */
468
    protected $customer;
469
470
    /**
471
     * @var string
472
     *
473
     * @ORM\Column(name="twitter", type="string", length=255, nullable=true)
474
     * @ConfigField(
475
     *      defaultValues={
476
     *          "dataaudit"={"auditable"=true},
477
     *          "importexport"={
478
     *              "order"=175
479
     *          }
480
     *      }
481
     * )
482
     */
483
    protected $twitter;
484
485
    /**
486
     * @var string
487
     *
488
     * @ORM\Column(name="linkedin", type="string", length=255, nullable=true)
489
     * @ConfigField(
490
     *      defaultValues={
491
     *          "dataaudit"={"auditable"=true},
492
     *          "importexport"={
493
     *              "order"=180
494
     *          }
495
     *      }
496
     * )
497
     */
498
    protected $linkedIn;
499
500
    /**
501
     * Constructor
502
     */
503 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...
504
    {
505
        parent::__construct();
506
507
        $this->opportunities = new ArrayCollection();
508
        $this->phones   = new ArrayCollection();
509
        $this->emails   = new ArrayCollection();
510
        $this->addresses = new ArrayCollection();
511
    }
512
513
    /**
514
     * Get id
515
     *
516
     * @return integer
517
     */
518
    public function getId()
519
    {
520
        return $this->id;
521
    }
522
523
    /**
524
     * Set topic
525
     *
526
     * @param string $name
527
     *
528
     * @return Lead
529
     */
530
    public function setName($name)
531
    {
532
        $this->name = $name;
533
534
        return $this;
535
    }
536
537
    /**
538
     * Get topic
539
     *
540
     * @return string
541
     */
542
    public function getName()
543
    {
544
        return $this->name;
545
    }
546
547
    /**
548
     * @param string $namePrefix
549
     *
550
     * @return Lead
551
     */
552
    public function setNamePrefix($namePrefix)
553
    {
554
        $this->namePrefix = $namePrefix;
555
556
        return $this;
557
    }
558
559
    /**
560
     * @return string
561
     */
562
    public function getNamePrefix()
563
    {
564
        return $this->namePrefix;
565
    }
566
567
    /**
568
     * Set first name
569
     *
570
     * @param string $firstName
571
     *
572
     * @return Lead
573
     */
574
    public function setFirstName($firstName)
575
    {
576
        $this->firstName = $firstName;
577
578
        return $this;
579
    }
580
581
    /**
582
     * Get first name
583
     *
584
     * @return string
585
     */
586
    public function getFirstName()
587
    {
588
        return $this->firstName;
589
    }
590
591
    /**
592
     * @return string
593
     */
594
    public function getMiddleName()
595
    {
596
        return $this->middleName;
597
    }
598
599
    /**
600
     * @param string $middleName
601
     *
602
     * @return Lead
603
     */
604
    public function setMiddleName($middleName)
605
    {
606
        $this->middleName = $middleName;
607
608
        return $this;
609
    }
610
611
    /**
612
     * Set last name
613
     *
614
     * @param string $lastName
615
     *
616
     * @return Lead
617
     */
618
    public function setLastName($lastName)
619
    {
620
        $this->lastName = $lastName;
621
622
        return $this;
623
    }
624
625
    /**
626
     * Get lastName
627
     *
628
     * @return string
629
     */
630
    public function getLastName()
631
    {
632
        return $this->lastName;
633
    }
634
635
    /**
636
     * @param string $nameSuffix
637
     *
638
     * @return Lead
639
     */
640
    public function setNameSuffix($nameSuffix)
641
    {
642
        $this->nameSuffix = $nameSuffix;
643
644
        return $this;
645
    }
646
647
    /**
648
     * @return string
649
     */
650
    public function getNameSuffix()
651
    {
652
        return $this->nameSuffix;
653
    }
654
655
    /**
656
     * Set job title
657
     *
658
     * @param string $jobTitle
659
     *
660
     * @return Lead
661
     */
662
    public function setJobTitle($jobTitle)
663
    {
664
        $this->jobTitle = $jobTitle;
665
666
        return $this;
667
    }
668
669
    /**
670
     * Get job title
671
     *
672
     * @return string
673
     */
674
    public function getJobTitle()
675
    {
676
        return $this->jobTitle;
677
    }
678
679
    /**
680
     * Set company name
681
     *
682
     * @param string $companyName
683
     *
684
     * @return Lead
685
     */
686
    public function setCompanyName($companyName)
687
    {
688
        $this->companyName = $companyName;
689
690
        return $this;
691
    }
692
693
    /**
694
     * Get company name
695
     *
696
     * @return string
697
     */
698
    public function getCompanyName()
699
    {
700
        return $this->companyName;
701
    }
702
703
    /**
704
     * Set website
705
     *
706
     * @param string $website
707
     *
708
     * @return Lead
709
     */
710
    public function setWebsite($website)
711
    {
712
        $this->website = $website;
713
714
        return $this;
715
    }
716
717
    /**
718
     * Get website
719
     *
720
     * @return string
721
     */
722
    public function getWebsite()
723
    {
724
        return $this->website;
725
    }
726
727
    /**
728
     * Set number of employees
729
     *
730
     * @param integer $numberOfEmployees
731
     *
732
     * @return Lead
733
     */
734
    public function setNumberOfEmployees($numberOfEmployees)
735
    {
736
        $this->numberOfEmployees = $numberOfEmployees;
737
738
        return $this;
739
    }
740
741
    /**
742
     * Get number of employees
743
     *
744
     * @return integer
745
     */
746
    public function getNumberOfEmployees()
747
    {
748
        return $this->numberOfEmployees;
749
    }
750
751
    /**
752
     * Set industry
753
     *
754
     * @param string $industry
755
     *
756
     * @return Lead
757
     */
758
    public function setIndustry($industry)
759
    {
760
        $this->industry = $industry;
761
762
        return $this;
763
    }
764
765
    /**
766
     * Get industry
767
     *
768
     * @return string
769
     */
770
    public function getIndustry()
771
    {
772
        return $this->industry;
773
    }
774
775
    /**
776
     * Add address
777
     *
778
     * @param AbstractAddress $address
779
     *
780
     * @return Lead
781
     */
782 View Code Duplication
    public function addAddress(AbstractAddress $address)
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...
783
    {
784
        /** @var LeadAddress $address */
785
        if (!$this->addresses->contains($address)) {
786
            $this->addresses->add($address);
787
            $address->setOwner($this);
788
        }
789
790
        return $this;
791
    }
792
793
    /**
794
     * Gets primary address if it's available.
795
     *
796
     * @return LeadAddress|null
797
     */
798 View Code Duplication
    public function getPrimaryAddress()
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...
799
    {
800
        $result = null;
801
802
        /** @var LeadAddress $address */
803
        foreach ($this->getAddresses() as $address) {
804
            if ($address->isPrimary()) {
805
                $result = $address;
806
                break;
807
            }
808
        }
809
810
        return $result;
811
    }
812
813
    /**
814
     * @param LeadAddress $address
815
     *
816
     * @return Lead
817
     */
818 View Code Duplication
    public function setPrimaryAddress(LeadAddress $address)
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...
819
    {
820
        if ($this->containsAddress($address)) {
821
            $address->setPrimary(true);
822
            /** @var LeadAddress $otherAddress */
823
            foreach ($this->getAddresses() as $otherAddress) {
824
                if (!$address->isEqual($otherAddress)) {
825
                    $otherAddress->setPrimary(false);
826
                }
827
            }
828
        }
829
830
        return $this;
831
    }
832
833
    /**
834
     * Get addresses
835
     *
836
     * @return Collection|AbstractAddress[]
837
     */
838
    public function getAddresses()
839
    {
840
        return $this->addresses;
841
    }
842
843
    /**
844
     * @param AbstractAddress $address
845
     * @return bool
846
     */
847
    public function containsAddress(AbstractAddress $address)
848
    {
849
        return $this->getAddresses()->contains($address);
850
    }
851
852
    /**
853
     * Remove address
854
     *
855
     * @param AbstractAddress $address
856
     * @return Lead
857
     */
858
    public function removeAddress(AbstractAddress $address)
859
    {
860
        if ($this->addresses->contains($address)) {
861
            $this->addresses->removeElement($address);
862
        }
863
864
        return $this;
865
    }
866
867
    /**
868
     * @deprecated since 1.10
869
     *
870
     * @return bool
871
     */
872
    public function hasAddress()
873
    {
874
        return false;
875
    }
876
877
    /**
878
     * @deprecated since 1.10
879
     *
880
     * @param $address
881
     * @return $this
882
     */
883
    public function setAddress($address)
0 ignored issues
show
Unused Code introduced by
The parameter $address is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
884
    {
885
        return $this;
886
    }
887
888
    /**
889
     * @param Contact $contact
890
     *
891
     * @return Lead
892
     */
893
    public function setContact($contact)
894
    {
895
        $this->contact = $contact;
896
897
        return $this;
898
    }
899
900
    /**
901
     * @return Contact
902
     */
903
    public function getContact()
904
    {
905
        return $this->contact;
906
    }
907
908
    /**
909
     * Get contact created date/time
910
     *
911
     * @return \DateTime
912
     */
913
    public function getCreatedAt()
914
    {
915
        return $this->createdAt;
916
    }
917
918
    /**
919
     * @param \DateTime $created
920
     *
921
     * @return Lead
922
     */
923
    public function setCreatedAt($created)
924
    {
925
        $this->createdAt = $created;
926
927
        return $this;
928
    }
929
930
    /**
931
     * Get lead last update date/time
932
     *
933
     * @return \DateTime
934
     */
935
    public function getUpdatedAt()
936
    {
937
        return $this->updatedAt;
938
    }
939
940
    /**
941
     * @param \DateTime $updated
942
     *
943
     * @return Lead
944
     */
945
    public function setUpdatedAt($updated)
946
    {
947
        $this->updatedAt = $updated;
948
949
        return $this;
950
    }
951
952
    /**
953
     * @return string
954
     */
955
    public function __toString()
956
    {
957
        return (string) $this->getName();
958
    }
959
960
    /**
961
     * Pre persist event listener
962
     *
963
     * @ORM\PrePersist
964
     */
965
    public function beforeSave()
966
    {
967
        $this->createdAt = new \DateTime('now', new \DateTimeZone('UTC'));
968
    }
969
970
    /**
971
     * Pre update event handler
972
     * @ORM\PreUpdate
973
     */
974
    public function beforeUpdate()
975
    {
976
        $this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
977
    }
978
979
    /**
980
     * @return User
981
     */
982
    public function getOwner()
983
    {
984
        return $this->owner;
985
    }
986
987
    /**
988
     * @param User $owningUser
989
     *
990
     * @return Lead
991
     */
992
    public function setOwner($owningUser)
993
    {
994
        $this->owner = $owningUser;
995
996
        return $this;
997
    }
998
999
    /**
1000
     * Get opportunities
1001
     *
1002
     * @return ArrayCollection
1003
     */
1004
    public function getOpportunities()
1005
    {
1006
        return $this->opportunities;
1007
    }
1008
1009
    /**
1010
     * Add opportunity
1011
     *
1012
     * @param Opportunity $opportunity
1013
     *
1014
     * @return Lead
1015
     */
1016 View Code Duplication
    public function addOpportunity(Opportunity $opportunity)
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...
1017
    {
1018
        if (!$this->opportunities->contains($opportunity)) {
1019
            $opportunity->setLead($this);
1020
            $this->opportunities->add($opportunity);
1021
        }
1022
1023
        return $this;
1024
    }
1025
1026
    /**
1027
     * @param Opportunity $opportunity
1028
     *
1029
     * @return Lead
1030
     */
1031 View Code Duplication
    public function removeOpportunity(Opportunity $opportunity)
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...
1032
    {
1033
        if ($this->opportunities->contains($opportunity)) {
1034
            $this->opportunities->removeElement($opportunity);
1035
            $opportunity->setLead(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Oro\Bundle\SalesBundle\Entity\Lead>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1036
        }
1037
1038
        return $this;
1039
    }
1040
1041
    /**
1042
     * @return string
1043
     */
1044
    public function getNotes()
1045
    {
1046
        return $this->notes;
1047
    }
1048
1049
    /**
1050
     * @param string $notes
1051
     *
1052
     * @return Lead
1053
     */
1054
    public function setNotes($notes)
1055
    {
1056
        $this->notes = $notes;
1057
1058
        return $this;
1059
    }
1060
1061
    /**
1062
     * @param B2bCustomer $customer
1063
     * @TODO remove null after BAP-5248
1064
     */
1065
    public function setCustomer(B2bCustomer $customer = null)
1066
    {
1067
        $this->customer = $customer;
1068
    }
1069
1070
    /**
1071
     * @return B2bCustomer
1072
     */
1073
    public function getCustomer()
1074
    {
1075
        return $this->customer;
1076
    }
1077
1078
    /**
1079
     * Set organization
1080
     *
1081
     * @param Organization $organization
1082
     * @return Lead
1083
     */
1084
    public function setOrganization(Organization $organization = null)
1085
    {
1086
        $this->organization = $organization;
1087
1088
        return $this;
1089
    }
1090
1091
    /**
1092
     * Get organization
1093
     *
1094
     * @return Organization
1095
     */
1096
    public function getOrganization()
1097
    {
1098
        return $this->organization;
1099
    }
1100
1101
    /**
1102
     * Remove Customer
1103
     *
1104
     * @return Lead
1105
     */
1106
    public function removeCustomer()
1107
    {
1108
        $this->customer = null;
1109
1110
        return $this;
1111
    }
1112
1113
    /**
1114
     * Set phones.
1115
     *
1116
     * This method could not be named setPhones because of bug CRM-253.
1117
     *
1118
     * @param Collection|LeadPhone[] $phones
1119
     *
1120
     * @return Lead
1121
     */
1122
    public function resetPhones($phones)
1123
    {
1124
        $this->phones->clear();
1125
1126
        foreach ($phones as $phone) {
1127
            $this->addPhone($phone);
1128
        }
1129
1130
        return $this;
1131
    }
1132
1133
    /**
1134
     * Add phone
1135
     *
1136
     * @param LeadPhone $phone
1137
     *
1138
     * @return Lead
1139
     */
1140 View Code Duplication
    public function addPhone(LeadPhone $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...
1141
    {
1142
        if (!$this->phones->contains($phone)) {
1143
            $this->phones->add($phone);
1144
            $phone->setOwner($this);
1145
        }
1146
1147
        return $this;
1148
    }
1149
1150
    /**
1151
     * Remove phone
1152
     *
1153
     * @param LeadPhone $phone
1154
     *
1155
     * @return Lead
1156
     */
1157
    public function removePhone(LeadPhone $phone)
1158
    {
1159
        if ($this->phones->contains($phone)) {
1160
            $this->phones->removeElement($phone);
1161
        }
1162
1163
        return $this;
1164
    }
1165
1166
    /**
1167
     * Get phones
1168
     *
1169
     * @return Collection|LeadPhone[]
1170
     */
1171
    public function getPhones()
1172
    {
1173
        return $this->phones;
1174
    }
1175
1176
    /**
1177
     * @param LeadPhone $phone
1178
     *
1179
     * @return bool
1180
     */
1181
    public function hasPhone(LeadPhone $phone)
1182
    {
1183
        return $this->getPhones()->contains($phone);
1184
    }
1185
1186
    /**
1187
     * Gets primary phone if it's available.
1188
     *
1189
     * @return LeadPhone|null
1190
     */
1191 View Code Duplication
    public function getPrimaryPhone()
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...
1192
    {
1193
        $result = null;
1194
1195
        foreach ($this->getPhones() as $phone) {
1196
            if ($phone->isPrimary()) {
1197
                $result = $phone;
1198
                break;
1199
            }
1200
        }
1201
1202
        return $result;
1203
    }
1204
1205
    /**
1206
     * @param LeadPhone $phone
1207
     *
1208
     * @return Lead
1209
     */
1210 View Code Duplication
    public function setPrimaryPhone(LeadPhone $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...
1211
    {
1212
        if ($this->hasPhone($phone)) {
1213
            $phone->setPrimary(true);
1214
            foreach ($this->getPhones() as $otherPhone) {
1215
                if (!$phone->isEqual($otherPhone)) {
1216
                    $otherPhone->setPrimary(false);
1217
                }
1218
            }
1219
        }
1220
1221
        return $this;
1222
    }
1223
1224
    /**
1225
     * Set emails.
1226
     **
1227
     * @param Collection|LeadEmail[] $emails
1228
     *
1229
     * @return Lead
1230
     */
1231
    public function resetEmails($emails)
1232
    {
1233
        $this->emails->clear();
1234
1235
        foreach ($emails as $email) {
1236
            $this->addEmail($email);
1237
        }
1238
1239
        return $this;
1240
    }
1241
1242
    /**
1243
     * Add email
1244
     *
1245
     * @param LeadEmail $email
1246
     *
1247
     * @return Lead
1248
     */
1249 View Code Duplication
    public function addEmail(LeadEmail $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...
1250
    {
1251
        if (!$this->emails->contains($email)) {
1252
            $this->emails->add($email);
1253
            $email->setOwner($this);
1254
        }
1255
1256
        return $this;
1257
    }
1258
1259
    /**
1260
     * Remove email
1261
     *
1262
     * @param LeadEmail $email
1263
     *
1264
     * @return Lead
1265
     */
1266
    public function removeEmail(LeadEmail $email)
1267
    {
1268
        if ($this->emails->contains($email)) {
1269
            $this->emails->removeElement($email);
1270
        }
1271
1272
        return $this;
1273
    }
1274
1275
    /**
1276
     * Get emails
1277
     *
1278
     * @return Collection|LeadEmail[]
1279
     */
1280
    public function getEmails()
1281
    {
1282
        return $this->emails;
1283
    }
1284
1285
    /**
1286
     * {@inheritdoc}
1287
     */
1288
    public function getEmail()
1289
    {
1290
        $primaryEmail = $this->getPrimaryEmail();
1291
        if (!$primaryEmail) {
1292
            return null;
1293
        }
1294
1295
        return $primaryEmail->getEmail();
1296
    }
1297
1298
    /**
1299
     * @param LeadEmail $email
1300
     * @return bool
1301
     */
1302
    public function hasEmail(LeadEmail $email)
1303
    {
1304
        return $this->getEmails()->contains($email);
1305
    }
1306
1307
    /**
1308
     * Gets primary email if it's available.
1309
     *
1310
     * @return LeadEmail|null
1311
     */
1312 View Code Duplication
    public function getPrimaryEmail()
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...
1313
    {
1314
        $result = null;
1315
1316
        foreach ($this->getEmails() as $email) {
1317
            if ($email->isPrimary()) {
1318
                $result = $email;
1319
                break;
1320
            }
1321
        }
1322
1323
        return $result;
1324
    }
1325
1326
    /**
1327
     * @return string
1328
     */
1329
    public function getTwitter()
1330
    {
1331
        return $this->twitter;
1332
    }
1333
1334
    /**
1335
     * @param string $twitter
1336
     */
1337
    public function setTwitter($twitter)
1338
    {
1339
        $this->twitter = $twitter;
1340
    }
1341
1342
    /**
1343
     * @return string
1344
     */
1345
    public function getLinkedIn()
1346
    {
1347
        return $this->linkedIn;
1348
    }
1349
1350
    /**
1351
     * @param string $linkedIn
1352
     */
1353
    public function setLinkedIn($linkedIn)
1354
    {
1355
        $this->linkedIn = $linkedIn;
1356
    }
1357
}
1358