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 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 |
||
74 | class Lead extends ExtendLead implements |
||
75 | FullNameInterface, |
||
76 | EmailHolderInterface, |
||
77 | ChannelAwareInterface |
||
78 | { |
||
79 | use ChannelEntityTrait; |
||
80 | |||
81 | /** |
||
82 | * @var integer |
||
83 | * |
||
84 | * @ORM\Column(name="id", type="integer") |
||
85 | * @ORM\Id |
||
86 | * @ORM\GeneratedValue(strategy="AUTO") |
||
87 | * @ConfigField( |
||
88 | * defaultValues={ |
||
89 | * "importexport"={ |
||
90 | * "order"=0 |
||
91 | * } |
||
92 | * } |
||
93 | * ) |
||
94 | */ |
||
95 | protected $id; |
||
96 | |||
97 | /** |
||
98 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\LeadStatus") |
||
99 | * @ORM\JoinColumn(name="status_name", referencedColumnName="name") |
||
100 | * @ConfigField( |
||
101 | * defaultValues={ |
||
102 | * "importexport"={ |
||
103 | * "order"=10, |
||
104 | * "short"=true |
||
105 | * } |
||
106 | * } |
||
107 | * ) |
||
108 | */ |
||
109 | protected $status; |
||
110 | |||
111 | /** |
||
112 | * @var Contact |
||
113 | * |
||
114 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact") |
||
115 | * @ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="SET NULL") |
||
116 | * @Oro\Versioned |
||
117 | * @ConfigField( |
||
118 | * defaultValues={ |
||
119 | * "dataaudit"={"auditable"=true}, |
||
120 | * "importexport"={ |
||
121 | * "order"=150, |
||
122 | * "short"=true |
||
123 | * } |
||
124 | * } |
||
125 | * ) |
||
126 | */ |
||
127 | protected $contact; |
||
128 | |||
129 | /** |
||
130 | * @var string |
||
131 | * |
||
132 | * @ORM\Column(name="name", type="string", length=255) |
||
133 | * @Oro\Versioned |
||
134 | * @ConfigField( |
||
135 | * defaultValues={ |
||
136 | * "dataaudit"={"auditable"=true}, |
||
137 | * "importexport"={ |
||
138 | * "order"=20, |
||
139 | * "identity"=true |
||
140 | * } |
||
141 | * } |
||
142 | * ) |
||
143 | */ |
||
144 | protected $name; |
||
145 | |||
146 | /** |
||
147 | * @var string |
||
148 | * |
||
149 | * @ORM\Column(name="name_prefix", type="string", length=255, nullable=true) |
||
150 | * @Oro\Versioned |
||
151 | * @ConfigField( |
||
152 | * defaultValues={ |
||
153 | * "dataaudit"={"auditable"=true}, |
||
154 | * "importexport"={ |
||
155 | * "order"=30 |
||
156 | * } |
||
157 | * } |
||
158 | * ) |
||
159 | */ |
||
160 | protected $namePrefix; |
||
161 | |||
162 | /** |
||
163 | * @var string |
||
164 | * |
||
165 | * @ORM\Column(name="first_name", type="string", length=255) |
||
166 | * @Oro\Versioned |
||
167 | * @ConfigField( |
||
168 | * defaultValues={ |
||
169 | * "dataaudit"={"auditable"=true}, |
||
170 | * "importexport"={ |
||
171 | * "order"=40 |
||
172 | * } |
||
173 | * } |
||
174 | * ) |
||
175 | */ |
||
176 | protected $firstName; |
||
177 | |||
178 | /** |
||
179 | * @var string |
||
180 | * |
||
181 | * @ORM\Column(name="middle_name", type="string", length=255, nullable=true) |
||
182 | * @Oro\Versioned |
||
183 | * @ConfigField( |
||
184 | * defaultValues={ |
||
185 | * "dataaudit"={"auditable"=true}, |
||
186 | * "importexport"={ |
||
187 | * "order"=50 |
||
188 | * } |
||
189 | * } |
||
190 | * ) |
||
191 | */ |
||
192 | protected $middleName; |
||
193 | |||
194 | /** |
||
195 | * @var string |
||
196 | * |
||
197 | * @ORM\Column(name="last_name", type="string", length=255) |
||
198 | * @Oro\Versioned |
||
199 | * @ConfigField( |
||
200 | * defaultValues={ |
||
201 | * "dataaudit"={"auditable"=true}, |
||
202 | * "importexport"={ |
||
203 | * "order"=60 |
||
204 | * } |
||
205 | * } |
||
206 | * ) |
||
207 | */ |
||
208 | protected $lastName; |
||
209 | |||
210 | /** |
||
211 | * @var string |
||
212 | * |
||
213 | * @ORM\Column(name="name_suffix", type="string", length=255, nullable=true) |
||
214 | * @Oro\Versioned |
||
215 | * @ConfigField( |
||
216 | * defaultValues={ |
||
217 | * "dataaudit"={"auditable"=true}, |
||
218 | * "importexport"={ |
||
219 | * "order"=70 |
||
220 | * } |
||
221 | * } |
||
222 | * ) |
||
223 | */ |
||
224 | protected $nameSuffix; |
||
225 | |||
226 | /** |
||
227 | * @var string |
||
228 | * |
||
229 | * @ORM\Column(name="job_title", type="string", length=255, nullable=true) |
||
230 | * @Oro\Versioned |
||
231 | * @ConfigField( |
||
232 | * defaultValues={ |
||
233 | * "dataaudit"={"auditable"=true}, |
||
234 | * "importexport"={ |
||
235 | * "order"=80 |
||
236 | * } |
||
237 | * } |
||
238 | * ) |
||
239 | */ |
||
240 | protected $jobTitle; |
||
241 | |||
242 | /** |
||
243 | * @var string |
||
244 | * |
||
245 | * @ORM\Column(name="phone_number", type="string", length=255, nullable=true) |
||
246 | * @Oro\Versioned |
||
247 | * @ConfigField( |
||
248 | * defaultValues={ |
||
249 | * "dataaudit"={"auditable"=true}, |
||
250 | * "importexport"={ |
||
251 | * "order"=90 |
||
252 | * } |
||
253 | * } |
||
254 | * ) |
||
255 | */ |
||
256 | protected $phoneNumber; |
||
257 | |||
258 | /** |
||
259 | * @var string |
||
260 | * |
||
261 | * @ORM\Column(name="email", type="string", length=255, nullable=true) |
||
262 | * @Oro\Versioned |
||
263 | * @ConfigField( |
||
264 | * defaultValues={ |
||
265 | * "dataaudit"={"auditable"=true}, |
||
266 | * "importexport"={ |
||
267 | * "order"=100 |
||
268 | * }, |
||
269 | * "entity"={ |
||
270 | * "contact_information"="email" |
||
271 | * } |
||
272 | * } |
||
273 | * ) |
||
274 | */ |
||
275 | protected $email; |
||
276 | |||
277 | /** |
||
278 | * @var string |
||
279 | * |
||
280 | * @ORM\Column(name="company_name", type="string", length=255, nullable=true) |
||
281 | * @Oro\Versioned |
||
282 | * @ConfigField( |
||
283 | * defaultValues={ |
||
284 | * "dataaudit"={"auditable"=true}, |
||
285 | * "importexport"={ |
||
286 | * "order"=110 |
||
287 | * } |
||
288 | * } |
||
289 | * ) |
||
290 | */ |
||
291 | protected $companyName; |
||
292 | |||
293 | /** |
||
294 | * @var string |
||
295 | * |
||
296 | * @ORM\Column(name="website", type="string", length=255, nullable=true) |
||
297 | * @Oro\Versioned |
||
298 | * @ConfigField( |
||
299 | * defaultValues={ |
||
300 | * "dataaudit"={"auditable"=true}, |
||
301 | * "importexport"={ |
||
302 | * "order"=120 |
||
303 | * } |
||
304 | * } |
||
305 | * ) |
||
306 | */ |
||
307 | protected $website; |
||
308 | |||
309 | /** |
||
310 | * @var integer |
||
311 | * |
||
312 | * @ORM\Column(name="number_of_employees", type="integer", nullable=true) |
||
313 | * @Oro\Versioned |
||
314 | * @ConfigField( |
||
315 | * defaultValues={ |
||
316 | * "dataaudit"={"auditable"=true}, |
||
317 | * "importexport"={ |
||
318 | * "order"=130 |
||
319 | * } |
||
320 | * } |
||
321 | * ) |
||
322 | */ |
||
323 | protected $numberOfEmployees; |
||
324 | |||
325 | /** |
||
326 | * @var string |
||
327 | * |
||
328 | * @ORM\Column(name="industry", type="string", length=255, nullable=true) |
||
329 | * @Oro\Versioned |
||
330 | * @ConfigField( |
||
331 | * defaultValues={ |
||
332 | * "dataaudit"={"auditable"=true}, |
||
333 | * "importexport"={ |
||
334 | * "order"=140 |
||
335 | * } |
||
336 | * } |
||
337 | * ) |
||
338 | */ |
||
339 | protected $industry; |
||
340 | |||
341 | /** |
||
342 | * @var Address |
||
343 | * |
||
344 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\AddressBundle\Entity\Address", cascade={"persist", "remove"}) |
||
345 | * @ORM\JoinColumn(name="address_id", referencedColumnName="id", onDelete="SET NULL", nullable=true) |
||
346 | * @ConfigField( |
||
347 | * defaultValues={ |
||
348 | * "dataaudit"={"auditable"=true}, |
||
349 | * "importexport"={ |
||
350 | * "order"=170, |
||
351 | * "full"=true |
||
352 | * } |
||
353 | * } |
||
354 | * ) |
||
355 | */ |
||
356 | protected $address; |
||
357 | |||
358 | /** |
||
359 | * @var \DateTime |
||
360 | * |
||
361 | * @ORM\Column(type="datetime") |
||
362 | * @ConfigField( |
||
363 | * defaultValues={ |
||
364 | * "entity"={ |
||
365 | * "label"="oro.ui.created_at" |
||
366 | * }, |
||
367 | * "importexport"={ |
||
368 | * "excluded"=true |
||
369 | * } |
||
370 | * } |
||
371 | * ) |
||
372 | */ |
||
373 | protected $createdAt; |
||
374 | |||
375 | /** |
||
376 | * @var \DateTime |
||
377 | * |
||
378 | * @ORM\Column(type="datetime", nullable=true) |
||
379 | * @ConfigField( |
||
380 | * defaultValues={ |
||
381 | * "entity"={ |
||
382 | * "label"="oro.ui.updated_at" |
||
383 | * }, |
||
384 | * "importexport"={ |
||
385 | * "excluded"=true |
||
386 | * } |
||
387 | * } |
||
388 | * ) |
||
389 | */ |
||
390 | protected $updatedAt; |
||
391 | |||
392 | /** |
||
393 | * @var User |
||
394 | * |
||
395 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
396 | * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL") |
||
397 | * @Oro\Versioned |
||
398 | * @ConfigField( |
||
399 | * defaultValues={ |
||
400 | * "dataaudit"={"auditable"=true}, |
||
401 | * "importexport"={ |
||
402 | * "order"=180, |
||
403 | * "short"=true |
||
404 | * } |
||
405 | * } |
||
406 | * ) |
||
407 | */ |
||
408 | protected $owner; |
||
409 | |||
410 | /** |
||
411 | * @var ArrayCollection |
||
412 | * |
||
413 | * @ORM\OneToMany(targetEntity="OroCRM\Bundle\SalesBundle\Entity\Opportunity", mappedBy="lead") |
||
414 | * @ConfigField( |
||
415 | * defaultValues={ |
||
416 | * "importexport"={ |
||
417 | * "order"=190, |
||
418 | * "short"=true |
||
419 | * } |
||
420 | * } |
||
421 | * ) |
||
422 | */ |
||
423 | protected $opportunities; |
||
424 | |||
425 | /** |
||
426 | * @var string |
||
427 | * |
||
428 | * @ORM\Column(name="notes", type="text", nullable=true) |
||
429 | * @Oro\Versioned |
||
430 | * @ConfigField( |
||
431 | * defaultValues={ |
||
432 | * "dataaudit"={"auditable"=true}, |
||
433 | * "importexport"={ |
||
434 | * "order"=140 |
||
435 | * } |
||
436 | * } |
||
437 | * ) |
||
438 | */ |
||
439 | protected $notes; |
||
440 | |||
441 | /** |
||
442 | * @var WorkflowItem |
||
443 | * |
||
444 | * @ORM\OneToOne(targetEntity="Oro\Bundle\WorkflowBundle\Entity\WorkflowItem") |
||
445 | * @ORM\JoinColumn(name="workflow_item_id", referencedColumnName="id", onDelete="SET NULL") |
||
446 | */ |
||
447 | protected $workflowItem; |
||
448 | |||
449 | /** |
||
450 | * @var WorkflowStep |
||
451 | * |
||
452 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\WorkflowBundle\Entity\WorkflowStep") |
||
453 | * @ORM\JoinColumn(name="workflow_step_id", referencedColumnName="id", onDelete="SET NULL") |
||
454 | */ |
||
455 | protected $workflowStep; |
||
456 | |||
457 | /** |
||
458 | * @var Organization |
||
459 | * |
||
460 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization") |
||
461 | * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") |
||
462 | */ |
||
463 | protected $organization; |
||
464 | |||
465 | /** |
||
466 | * @var B2bCustomer |
||
467 | * |
||
468 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\B2bCustomer", inversedBy="leads") |
||
469 | * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="SET NULL") |
||
470 | * @Oro\Versioned |
||
471 | * @ConfigField( |
||
472 | * defaultValues={ |
||
473 | * "dataaudit"={"auditable"=true}, |
||
474 | * "importexport"={ |
||
475 | * "order"=160, |
||
476 | * "short"=true |
||
477 | * } |
||
478 | * } |
||
479 | * ) |
||
480 | */ |
||
481 | protected $customer; |
||
482 | |||
483 | /** |
||
484 | * Constructor |
||
485 | */ |
||
486 | public function __construct() |
||
487 | { |
||
488 | parent::__construct(); |
||
489 | |||
490 | $this->opportunities = new ArrayCollection(); |
||
491 | } |
||
492 | |||
493 | /** |
||
494 | * Get id |
||
495 | * |
||
496 | * @return integer |
||
497 | */ |
||
498 | public function getId() |
||
502 | |||
503 | /** |
||
504 | * Set topic |
||
505 | * |
||
506 | * @param string $name |
||
507 | * |
||
508 | * @return Lead |
||
509 | */ |
||
510 | public function setName($name) |
||
511 | { |
||
512 | $this->name = $name; |
||
513 | |||
514 | return $this; |
||
515 | } |
||
516 | |||
517 | /** |
||
518 | * Get topic |
||
519 | * |
||
520 | * @return string |
||
521 | */ |
||
522 | public function getName() |
||
526 | |||
527 | /** |
||
528 | * @param string $namePrefix |
||
529 | * |
||
530 | * @return Lead |
||
531 | */ |
||
532 | public function setNamePrefix($namePrefix) |
||
533 | { |
||
534 | $this->namePrefix = $namePrefix; |
||
535 | |||
536 | return $this; |
||
537 | } |
||
538 | |||
539 | /** |
||
540 | * @return string |
||
541 | */ |
||
542 | public function getNamePrefix() |
||
546 | |||
547 | /** |
||
548 | * Set first name |
||
549 | * |
||
550 | * @param string $firstName |
||
551 | * |
||
552 | * @return Lead |
||
553 | */ |
||
554 | public function setFirstName($firstName) |
||
555 | { |
||
556 | $this->firstName = $firstName; |
||
557 | |||
558 | return $this; |
||
559 | } |
||
560 | |||
561 | /** |
||
562 | * Get first name |
||
563 | * |
||
564 | * @return string |
||
565 | */ |
||
566 | public function getFirstName() |
||
570 | |||
571 | /** |
||
572 | * @return string |
||
573 | */ |
||
574 | public function getMiddleName() |
||
578 | |||
579 | /** |
||
580 | * @param string $middleName |
||
581 | * |
||
582 | * @return Lead |
||
583 | */ |
||
584 | public function setMiddleName($middleName) |
||
585 | { |
||
586 | $this->middleName = $middleName; |
||
587 | |||
588 | return $this; |
||
589 | } |
||
590 | |||
591 | /** |
||
592 | * Set last name |
||
593 | * |
||
594 | * @param string $lastName |
||
595 | * |
||
596 | * @return Lead |
||
597 | */ |
||
598 | public function setLastName($lastName) |
||
599 | { |
||
600 | $this->lastName = $lastName; |
||
601 | |||
602 | return $this; |
||
603 | } |
||
604 | |||
605 | /** |
||
606 | * Get lastName |
||
607 | * |
||
608 | * @return string |
||
609 | */ |
||
610 | public function getLastName() |
||
614 | |||
615 | /** |
||
616 | * @param string $nameSuffix |
||
617 | * |
||
618 | * @return Lead |
||
619 | */ |
||
620 | public function setNameSuffix($nameSuffix) |
||
621 | { |
||
622 | $this->nameSuffix = $nameSuffix; |
||
623 | |||
624 | return $this; |
||
625 | } |
||
626 | |||
627 | /** |
||
628 | * @return string |
||
629 | */ |
||
630 | public function getNameSuffix() |
||
634 | |||
635 | /** |
||
636 | * Set job title |
||
637 | * |
||
638 | * @param string $jobTitle |
||
639 | * |
||
640 | * @return Lead |
||
641 | */ |
||
642 | public function setJobTitle($jobTitle) |
||
643 | { |
||
644 | $this->jobTitle = $jobTitle; |
||
645 | |||
646 | return $this; |
||
647 | } |
||
648 | |||
649 | /** |
||
650 | * Get job title |
||
651 | * |
||
652 | * @return string |
||
653 | */ |
||
654 | public function getJobTitle() |
||
658 | |||
659 | /** |
||
660 | * Set phone number |
||
661 | * |
||
662 | * @param string $phoneNumber |
||
663 | * |
||
664 | * @return Lead |
||
665 | */ |
||
666 | public function setPhoneNumber($phoneNumber) |
||
667 | { |
||
668 | $this->phoneNumber = $phoneNumber; |
||
669 | |||
670 | return $this; |
||
671 | } |
||
672 | |||
673 | /** |
||
674 | * Get phone number |
||
675 | * |
||
676 | * @return string |
||
677 | */ |
||
678 | public function getPhoneNumber() |
||
682 | |||
683 | /** |
||
684 | * Set email |
||
685 | * |
||
686 | * @param string $email |
||
687 | * |
||
688 | * @return Lead |
||
689 | */ |
||
690 | public function setEmail($email) |
||
691 | { |
||
692 | $this->email = $email; |
||
693 | |||
694 | return $this; |
||
695 | } |
||
696 | |||
697 | /** |
||
698 | * Get email |
||
699 | * |
||
700 | * @return string |
||
701 | */ |
||
702 | public function getEmail() |
||
706 | |||
707 | /** |
||
708 | * Set company name |
||
709 | * |
||
710 | * @param string $companyName |
||
711 | * |
||
712 | * @return Lead |
||
713 | */ |
||
714 | public function setCompanyName($companyName) |
||
715 | { |
||
716 | $this->companyName = $companyName; |
||
717 | |||
718 | return $this; |
||
719 | } |
||
720 | |||
721 | /** |
||
722 | * Get company name |
||
723 | * |
||
724 | * @return string |
||
725 | */ |
||
726 | public function getCompanyName() |
||
730 | |||
731 | /** |
||
732 | * Set website |
||
733 | * |
||
734 | * @param string $website |
||
735 | * |
||
736 | * @return Lead |
||
737 | */ |
||
738 | public function setWebsite($website) |
||
739 | { |
||
740 | $this->website = $website; |
||
741 | |||
742 | return $this; |
||
743 | } |
||
744 | |||
745 | /** |
||
746 | * Get website |
||
747 | * |
||
748 | * @return string |
||
749 | */ |
||
750 | public function getWebsite() |
||
754 | |||
755 | /** |
||
756 | * Set number of employees |
||
757 | * |
||
758 | * @param integer $numberOfEmployees |
||
759 | * |
||
760 | * @return Lead |
||
761 | */ |
||
762 | public function setNumberOfEmployees($numberOfEmployees) |
||
763 | { |
||
764 | $this->numberOfEmployees = $numberOfEmployees; |
||
765 | |||
766 | return $this; |
||
767 | } |
||
768 | |||
769 | /** |
||
770 | * Get number of employees |
||
771 | * |
||
772 | * @return integer |
||
773 | */ |
||
774 | public function getNumberOfEmployees() |
||
778 | |||
779 | /** |
||
780 | * Set industry |
||
781 | * |
||
782 | * @param string $industry |
||
783 | * |
||
784 | * @return Lead |
||
785 | */ |
||
786 | public function setIndustry($industry) |
||
787 | { |
||
788 | $this->industry = $industry; |
||
789 | |||
790 | return $this; |
||
791 | } |
||
792 | |||
793 | /** |
||
794 | * Get industry |
||
795 | * |
||
796 | * @return string |
||
797 | */ |
||
798 | public function getIndustry() |
||
802 | |||
803 | /** |
||
804 | * @return LeadStatus |
||
805 | */ |
||
806 | public function getStatus() |
||
810 | |||
811 | /** |
||
812 | * @param LeadStatus $status |
||
813 | * |
||
814 | * @return Lead |
||
815 | */ |
||
816 | public function setStatus($status) |
||
817 | { |
||
818 | $this->status = $status; |
||
819 | |||
820 | return $this; |
||
821 | } |
||
822 | |||
823 | /** |
||
824 | * Get address |
||
825 | * |
||
826 | * @return Address |
||
827 | */ |
||
828 | public function getAddress() |
||
832 | |||
833 | /** |
||
834 | * Set address |
||
835 | * |
||
836 | * @param Address $address |
||
837 | * |
||
838 | * @return Lead |
||
839 | */ |
||
840 | public function setAddress($address) |
||
841 | { |
||
842 | $this->address = $address; |
||
843 | |||
844 | return $this; |
||
845 | } |
||
846 | |||
847 | /** |
||
848 | * @param Contact $contact |
||
849 | * |
||
850 | * @return Lead |
||
851 | */ |
||
852 | public function setContact($contact) |
||
853 | { |
||
854 | $this->contact = $contact; |
||
855 | |||
856 | return $this; |
||
857 | } |
||
858 | |||
859 | /** |
||
860 | * @return Contact |
||
861 | */ |
||
862 | public function getContact() |
||
866 | |||
867 | /** |
||
868 | * Get contact created date/time |
||
869 | * |
||
870 | * @return \DateTime |
||
871 | */ |
||
872 | public function getCreatedAt() |
||
876 | |||
877 | /** |
||
878 | * @param \DateTime $created |
||
879 | * |
||
880 | * @return Lead |
||
881 | */ |
||
882 | public function setCreatedAt($created) |
||
883 | { |
||
884 | $this->createdAt = $created; |
||
885 | |||
886 | return $this; |
||
887 | } |
||
888 | |||
889 | /** |
||
890 | * Get contact last update date/time |
||
891 | * |
||
892 | * @return \DateTime |
||
893 | */ |
||
894 | public function getUpdatedAt() |
||
898 | |||
899 | /** |
||
900 | * @param \DateTime $updated |
||
901 | * |
||
902 | * @return Lead |
||
903 | */ |
||
904 | public function setUpdatedAt($updated) |
||
905 | { |
||
906 | $this->updatedAt = $updated; |
||
907 | |||
908 | return $this; |
||
909 | } |
||
910 | |||
911 | /** |
||
912 | * @return string |
||
913 | */ |
||
914 | public function __toString() |
||
918 | |||
919 | /** |
||
920 | * Pre persist event listener |
||
921 | * |
||
922 | * @ORM\PrePersist |
||
923 | */ |
||
924 | public function beforeSave() |
||
928 | |||
929 | /** |
||
930 | * Pre update event handler |
||
931 | * @ORM\PreUpdate |
||
932 | */ |
||
933 | public function beforeUpdate() |
||
937 | |||
938 | /** |
||
939 | * @return User |
||
940 | */ |
||
941 | public function getOwner() |
||
945 | |||
946 | /** |
||
947 | * @param User $owningUser |
||
948 | * |
||
949 | * @return Lead |
||
950 | */ |
||
951 | public function setOwner($owningUser) |
||
952 | { |
||
953 | $this->owner = $owningUser; |
||
954 | |||
955 | return $this; |
||
956 | } |
||
957 | |||
958 | /** |
||
959 | * Get opportunities |
||
960 | * |
||
961 | * @return Opportunity[] |
||
962 | */ |
||
963 | public function getOpportunities() |
||
967 | |||
968 | /** |
||
969 | * Add opportunity |
||
970 | * |
||
971 | * @param Opportunity $opportunity |
||
972 | * |
||
973 | * @return Lead |
||
974 | */ |
||
975 | View Code Duplication | public function addOpportunity(Opportunity $opportunity) |
|
|
|||
976 | { |
||
977 | if (!$this->opportunities->contains($opportunity)) { |
||
978 | $opportunity->setLead($this); |
||
979 | $this->opportunities->add($opportunity); |
||
980 | } |
||
981 | |||
982 | return $this; |
||
983 | } |
||
984 | |||
985 | /** |
||
986 | * @param Opportunity $opportunity |
||
987 | * |
||
988 | * @return Lead |
||
989 | */ |
||
990 | View Code Duplication | public function removeOpportunity(Opportunity $opportunity) |
|
991 | { |
||
992 | if ($this->opportunities->contains($opportunity)) { |
||
993 | $this->opportunities->removeElement($opportunity); |
||
994 | $opportunity->setLead(null); |
||
995 | } |
||
996 | |||
997 | return $this; |
||
998 | } |
||
999 | |||
1000 | /** |
||
1001 | * @return string |
||
1002 | */ |
||
1003 | public function getNotes() |
||
1007 | |||
1008 | /** |
||
1009 | * @param string $notes |
||
1010 | * |
||
1011 | * @return Lead |
||
1012 | */ |
||
1013 | public function setNotes($notes) |
||
1014 | { |
||
1015 | $this->notes = $notes; |
||
1016 | |||
1017 | return $this; |
||
1018 | } |
||
1019 | |||
1020 | /** |
||
1021 | * @param WorkflowItem $workflowItem |
||
1022 | * |
||
1023 | * @return Lead |
||
1024 | */ |
||
1025 | public function setWorkflowItem($workflowItem) |
||
1026 | { |
||
1027 | $this->workflowItem = $workflowItem; |
||
1028 | |||
1029 | return $this; |
||
1030 | } |
||
1031 | |||
1032 | /** |
||
1033 | * @return WorkflowItem |
||
1034 | */ |
||
1035 | public function getWorkflowItem() |
||
1039 | |||
1040 | /** |
||
1041 | * @param WorkflowItem $workflowStep |
||
1042 | * |
||
1043 | * @return Lead |
||
1044 | */ |
||
1045 | public function setWorkflowStep($workflowStep) |
||
1046 | { |
||
1047 | $this->workflowStep = $workflowStep; |
||
1048 | |||
1049 | return $this; |
||
1050 | } |
||
1051 | |||
1052 | /** |
||
1053 | * @return WorkflowStep |
||
1054 | */ |
||
1055 | public function getWorkflowStep() |
||
1059 | |||
1060 | /** |
||
1061 | * @param B2bCustomer $customer |
||
1062 | * @TODO remove null after BAP-5248 |
||
1063 | */ |
||
1064 | public function setCustomer(B2bCustomer $customer = null) |
||
1068 | |||
1069 | /** |
||
1070 | * @return B2bCustomer |
||
1071 | */ |
||
1072 | public function getCustomer() |
||
1076 | |||
1077 | /** |
||
1078 | * @ORM\PrePersist |
||
1079 | */ |
||
1080 | public function prePersist(LifecycleEventArgs $eventArgs) |
||
1081 | { |
||
1082 | if (!$this->status) { |
||
1083 | $em = $eventArgs->getEntityManager(); |
||
1084 | /** @var LeadStatus $defaultStatus */ |
||
1085 | $defaultStatus = $em->getReference('OroCRMSalesBundle:LeadStatus', 'new'); |
||
1086 | $this->setStatus($defaultStatus); |
||
1087 | } |
||
1088 | } |
||
1089 | |||
1090 | /** |
||
1091 | * Set organization |
||
1092 | * |
||
1093 | * @param Organization $organization |
||
1094 | * @return Lead |
||
1095 | */ |
||
1096 | public function setOrganization(Organization $organization = null) |
||
1097 | { |
||
1098 | $this->organization = $organization; |
||
1099 | |||
1100 | return $this; |
||
1101 | } |
||
1102 | |||
1103 | /** |
||
1104 | * Get organization |
||
1105 | * |
||
1106 | * @return Organization |
||
1107 | */ |
||
1108 | public function getOrganization() |
||
1112 | |||
1113 | /** |
||
1114 | * Remove Customer |
||
1115 | * |
||
1116 | * @return Lead |
||
1117 | */ |
||
1118 | public function removeCustomer() |
||
1122 | } |
||
1123 |
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.