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 |
||
37 | class CommandHandler extends OfferCommandHandler implements LoggerAwareInterface |
||
38 | { |
||
39 | use LoggerAwareTrait; |
||
40 | |||
41 | /** |
||
42 | * @return string |
||
43 | */ |
||
44 | protected function getAddLabelClassName() |
||
48 | |||
49 | /** |
||
50 | * @return string |
||
51 | */ |
||
52 | protected function getRemoveLabelClassName() |
||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | protected function getAddImageClassName() |
||
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | protected function getUpdateImageClassName() |
||
72 | |||
73 | /** |
||
74 | * @return string |
||
75 | */ |
||
76 | protected function getRemoveImageClassName() |
||
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | protected function getSelectMainImageClassName() |
||
88 | |||
89 | /** |
||
90 | * @return string |
||
91 | */ |
||
92 | protected function getUpdateTitleClassName() |
||
93 | { |
||
94 | return UpdateTitle::class; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @return string |
||
99 | */ |
||
100 | protected function getUpdateDescriptionClassName() |
||
101 | { |
||
102 | return UpdateDescription::class; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @inheritdoc |
||
107 | */ |
||
108 | protected function getUpdateCalendarClassName() |
||
109 | { |
||
110 | return UpdateCalendar::class; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @return string |
||
115 | */ |
||
116 | protected function getUpdateTypicalAgeRangeClassName() |
||
120 | |||
121 | /** |
||
122 | * @return string |
||
123 | */ |
||
124 | protected function getDeleteTypicalAgeRangeClassName() |
||
128 | |||
129 | /** |
||
130 | * @return string |
||
131 | */ |
||
132 | protected function getUpdateOrganizerClassName() |
||
136 | |||
137 | /** |
||
138 | * @return string |
||
139 | */ |
||
140 | protected function getDeleteOrganizerClassName() |
||
144 | |||
145 | /** |
||
146 | * @return string |
||
147 | */ |
||
148 | protected function getUpdateContactPointClassName() |
||
152 | |||
153 | /** |
||
154 | * @return string |
||
155 | */ |
||
156 | protected function getUpdateBookingInfoClassName() |
||
160 | |||
161 | /** |
||
162 | * @return string |
||
163 | */ |
||
164 | protected function getUpdatePriceInfoClassName() |
||
168 | |||
169 | /** |
||
170 | * @return string |
||
171 | */ |
||
172 | protected function getDeleteOfferClassName() |
||
176 | |||
177 | protected function getPublishClassName() |
||
181 | |||
182 | protected function getApproveClassName() |
||
186 | |||
187 | protected function getRejectClassName() |
||
191 | |||
192 | protected function getFlagAsDuplicateClassName() |
||
196 | |||
197 | protected function getFlagAsInappropriateClassName() |
||
201 | |||
202 | /** |
||
203 | * @param UpdateAddress $updateAddress |
||
204 | */ |
||
205 | protected function handleUpdateAddress(UpdateAddress $updateAddress) |
||
212 | |||
213 | /** |
||
214 | * Handle the update of facilities for a place. |
||
215 | * @param UpdateFacilities $updateFacilities |
||
216 | */ |
||
217 | public function handleUpdateFacilities(UpdateFacilities $updateFacilities) |
||
229 | |||
230 | /** |
||
231 | * Handle an update the major info command. |
||
232 | * @param UpdateMajorInfo $updateMajorInfo |
||
233 | */ |
||
234 | View Code Duplication | public function handleUpdateMajorInfo(UpdateMajorInfo $updateMajorInfo) |
|
251 | } |
||
252 |
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.