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 |
||
38 | class EventCommandHandler extends OfferCommandHandler implements LoggerAwareInterface |
||
39 | { |
||
40 | use LoggerAwareTrait; |
||
41 | |||
42 | /** |
||
43 | * Handle an update the major info command. |
||
44 | * @param UpdateMajorInfo $updateMajorInfo |
||
45 | */ |
||
46 | View Code Duplication | public function handleUpdateMajorInfo(UpdateMajorInfo $updateMajorInfo) |
|
62 | |||
63 | /** |
||
64 | * @param UpdateLocation $updateLocation |
||
65 | */ |
||
66 | public function handleUpdateLocation(UpdateLocation $updateLocation) |
||
75 | |||
76 | /** |
||
77 | * @param UpdateAudience $updateAudience |
||
78 | */ |
||
79 | public function handleUpdateAudience(UpdateAudience $updateAudience) |
||
88 | |||
89 | /** |
||
90 | * @return string |
||
91 | */ |
||
92 | protected function getAddLabelClassName() |
||
96 | |||
97 | /** |
||
98 | * @return string |
||
99 | */ |
||
100 | protected function getRemoveLabelClassName() |
||
104 | |||
105 | /** |
||
106 | * @return string |
||
107 | */ |
||
108 | protected function getAddImageClassName() |
||
112 | |||
113 | /** |
||
114 | * @return string |
||
115 | */ |
||
116 | protected function getUpdateImageClassName() |
||
120 | |||
121 | /** |
||
122 | * @return string |
||
123 | */ |
||
124 | protected function getRemoveImageClassName() |
||
128 | |||
129 | /** |
||
130 | * @return string |
||
131 | */ |
||
132 | protected function getSelectMainImageClassName() |
||
136 | |||
137 | /** |
||
138 | * @return string |
||
139 | */ |
||
140 | protected function getUpdateTitleClassName() |
||
141 | { |
||
142 | return UpdateTitle::class; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @return string |
||
147 | */ |
||
148 | protected function getUpdateDescriptionClassName() |
||
152 | |||
153 | /** |
||
154 | * @inheritdoc |
||
155 | */ |
||
156 | protected function getUpdateCalendarClassName() |
||
160 | |||
161 | /** |
||
162 | * @return string |
||
163 | */ |
||
164 | protected function getUpdateTypicalAgeRangeClassName() |
||
168 | |||
169 | /** |
||
170 | * @return string |
||
171 | */ |
||
172 | protected function getDeleteTypicalAgeRangeClassName() |
||
176 | |||
177 | /** |
||
178 | * @return string |
||
179 | */ |
||
180 | protected function getUpdateOrganizerClassName() |
||
184 | |||
185 | /** |
||
186 | * @return string |
||
187 | */ |
||
188 | protected function getDeleteOrganizerClassName() |
||
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | protected function getUpdateContactPointClassName() |
||
200 | |||
201 | /** |
||
202 | * @return string |
||
203 | */ |
||
204 | protected function getUpdateBookingInfoClassName() |
||
208 | |||
209 | /** |
||
210 | * @return string |
||
211 | */ |
||
212 | protected function getUpdatePriceInfoClassName() |
||
216 | |||
217 | /** |
||
218 | * @return string |
||
219 | */ |
||
220 | protected function getDeleteOfferClassName() |
||
224 | |||
225 | protected function getPublishClassName() |
||
229 | |||
230 | protected function getApproveClassName() |
||
234 | |||
235 | protected function getRejectClassName() |
||
239 | |||
240 | protected function getFlagAsDuplicateClassName() |
||
244 | |||
245 | protected function getFlagAsInappropriateClassName() |
||
249 | } |
||
250 |
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.