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 |
||
33 | class Warcraft extends AbstractBattleNet |
||
34 | { |
||
35 | private $_path = 'wow'; |
||
36 | |||
37 | /** |
||
38 | * @param int $achievementId |
||
39 | * |
||
40 | * @return AchievementResponse |
||
41 | */ |
||
42 | public function getAchievement($achievementId) |
||
47 | |||
48 | /** |
||
49 | * @param string $realmSlug |
||
50 | * |
||
51 | * @return AuctionResponse |
||
52 | * @throws BattleNetException |
||
53 | */ |
||
54 | public function getAuctions($realmSlug) |
||
70 | |||
71 | /** |
||
72 | * @return BattleGroupResponse[] |
||
73 | */ |
||
74 | public function getBattleGroups() |
||
85 | |||
86 | /** |
||
87 | * @param int $abilityId |
||
88 | * |
||
89 | * @return BattlePetAbilityResponse |
||
90 | */ |
||
91 | public function getBattlePetAbility($abilityId) |
||
96 | |||
97 | /** |
||
98 | * @param int $speciesId |
||
99 | * |
||
100 | * @return BattlePetSpeciesResponse |
||
101 | */ |
||
102 | public function getBattlePetSpecies($speciesId) |
||
107 | |||
108 | /** |
||
109 | * @param int $speciesId |
||
110 | * @param int $level |
||
111 | * @param int $breedId |
||
112 | * @param int $qualityId |
||
113 | * |
||
114 | * @return BattlePetStatsResponse |
||
115 | */ |
||
116 | public function getBattlePetStats( |
||
130 | |||
131 | /** |
||
132 | * @param string $realmSlug |
||
133 | * |
||
134 | * @return ChallengeRealmResponse |
||
135 | */ |
||
136 | public function getChallengeRealmLeaderboard($realmSlug) |
||
141 | |||
142 | /** |
||
143 | * @return ChallengeRegionResponse |
||
144 | */ |
||
145 | public function getChallengeRegionLeaderboard() |
||
150 | |||
151 | /** |
||
152 | * @param string $realmSlug |
||
153 | * @param string $guildName |
||
154 | * @param array $fields |
||
155 | * |
||
156 | * @return GuildResponse |
||
157 | */ |
||
158 | public function getGuild($realmSlug, $guildName, $fields = []) |
||
167 | |||
168 | /** |
||
169 | * @return GuildAchievementsResponse |
||
170 | */ |
||
171 | public function getGuildAchievements() |
||
176 | |||
177 | /** |
||
178 | * @return GuildPerksResponse |
||
179 | */ |
||
180 | public function getGuildPerks() |
||
185 | |||
186 | /** |
||
187 | * @return GuildRewardsResponse |
||
188 | */ |
||
189 | public function getGuildRewards() |
||
194 | |||
195 | /** |
||
196 | * @param int $itemId |
||
197 | * |
||
198 | * @return ItemResponse |
||
199 | */ |
||
200 | public function getItem($itemId) |
||
205 | |||
206 | /** |
||
207 | * @return ItemClassesResponse |
||
208 | */ |
||
209 | public function getItemClasses() |
||
214 | |||
215 | /** |
||
216 | * @param int $setId |
||
217 | * |
||
218 | * @return ItemSetResponse |
||
219 | */ |
||
220 | public function getItemSet($setId) |
||
225 | |||
226 | /** |
||
227 | * @return PetTypeResponse[] |
||
228 | */ |
||
229 | public function getPetTypes() |
||
240 | |||
241 | /** |
||
242 | * @param string $realmSlug |
||
243 | * @param string $character |
||
244 | * @param array $fields |
||
245 | * |
||
246 | * @return CharacterResponse |
||
247 | */ |
||
248 | public function getCharacter($realmSlug, $character, $fields = []) |
||
262 | |||
263 | /** |
||
264 | * @return CharacterAchievementsResponse |
||
265 | */ |
||
266 | public function getCharacterAchievements() |
||
271 | |||
272 | /** |
||
273 | * @return CharacterClassResponse[] |
||
274 | */ |
||
275 | View Code Duplication | public function getCharacterClasses() |
|
286 | |||
287 | /** |
||
288 | * @param string $bracket |
||
289 | * |
||
290 | * @return PvpLeaderboardResponse[] |
||
291 | */ |
||
292 | View Code Duplication | public function getPvpLeaderboard($bracket) |
|
303 | |||
304 | /** |
||
305 | * @param int $questId |
||
306 | * |
||
307 | * @return QuestResponse |
||
308 | */ |
||
309 | public function getQuest($questId) |
||
314 | |||
315 | /** |
||
316 | * @return RaceResponse[] |
||
317 | */ |
||
318 | public function getRaces() |
||
329 | |||
330 | /** |
||
331 | * @return RealmResponse[] |
||
332 | */ |
||
333 | public function getRealms() |
||
344 | |||
345 | /** |
||
346 | * @param int $recipeId |
||
347 | * |
||
348 | * @return RecipeResponse |
||
349 | */ |
||
350 | public function getRecipe($recipeId) |
||
355 | |||
356 | /** |
||
357 | * @param int $spellId |
||
358 | * |
||
359 | * @return SpellResponse |
||
360 | */ |
||
361 | public function getSpell($spellId) |
||
366 | |||
367 | /** |
||
368 | * @return TalentResponse[] |
||
369 | */ |
||
370 | public function getTalents() |
||
381 | } |
||
382 |
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.