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:
1 | <?php |
||
21 | class IncidentEventSubscriber implements EventSubscriber |
||
22 | { |
||
23 | protected static $typeEventPolitic =[ |
||
24 | IncidentInterface::TYPE_URGENT => [ |
||
25 | EmailNotificationType::class, |
||
26 | FileNotificationType::class, |
||
27 | RequestNotificationType::class, |
||
28 | ], |
||
29 | IncidentInterface::TYPE_WARNING => [ |
||
30 | EmailNotificationType::class, |
||
31 | RequestNotificationType::class, |
||
32 | ], |
||
33 | IncidentInterface::TYPE_MINOR => [ |
||
34 | EmailNotificationType::class, |
||
35 | RequestNotificationType::class, |
||
36 | ], |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * @var IncidentSirenCollection |
||
41 | */ |
||
42 | private $incidentSirenCollection; |
||
43 | |||
44 | /** |
||
45 | * IncidentHandler constructor. |
||
46 | * @param IncidentSirenCollection $incidentSirenC |
||
47 | */ |
||
48 | public function __construct($incidentSirenC) |
||
52 | |||
53 | /** |
||
54 | * @return array |
||
55 | */ |
||
56 | public function getSubscribedEvents() |
||
63 | |||
64 | /** |
||
65 | * @param PreUpdateEventArgs $args |
||
66 | */ |
||
67 | View Code Duplication | public function preUpdate(PreUpdateEventArgs $args) |
|
77 | |||
78 | /** |
||
79 | * @param LifecycleEventArgs $args |
||
80 | */ |
||
81 | View Code Duplication | public function prePersist(LifecycleEventArgs $args) |
|
89 | |||
90 | /** |
||
91 | * @return IncidentSirenCollection |
||
92 | */ |
||
93 | public function getIncidentSirenCollection() |
||
97 | |||
98 | /** |
||
99 | * @param IncidentSirenCollection $incidentSiren |
||
100 | */ |
||
101 | protected function setIncidentSirenCollection(IncidentSirenCollection $incidentSiren) |
||
105 | |||
106 | /** |
||
107 | * @param IncidentInterface $entity |
||
108 | */ |
||
109 | protected function preUpdateIncidentStatus(IncidentInterface $entity) |
||
120 | |||
121 | /** |
||
122 | * @param $type |
||
123 | * @param $notificationTypeI |
||
124 | * @return bool |
||
125 | */ |
||
126 | protected function checkIsNotificationAllow($type, $notificationTypeI) |
||
139 | } |
||
140 |
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.