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 |
||
12 | class StarCraft extends AbstractBattleNet |
||
13 | { |
||
14 | private $_path = 'sc2'; |
||
15 | |||
16 | /** |
||
17 | * @param int $id |
||
18 | * @param int $region |
||
19 | * @param string $name |
||
20 | * |
||
21 | * @return ProfileResponse |
||
22 | */ |
||
23 | View Code Duplication | public function getProfile($id, $region, $name) |
|
30 | |||
31 | /** |
||
32 | * @param int $id |
||
33 | * @param int $region |
||
34 | * @param string $name |
||
35 | * |
||
36 | * @return LaddersResponse |
||
37 | */ |
||
38 | View Code Duplication | public function getProfileLadders($id, $region, $name) |
|
45 | |||
46 | /** |
||
47 | * @param int $id |
||
48 | * @param int $region |
||
49 | * @param string $name |
||
50 | * |
||
51 | * @return MatchHistoryResponse[] |
||
52 | */ |
||
53 | public function getProfileMatches($id, $region, $name) |
||
66 | |||
67 | /** |
||
68 | * @param string $ladderId |
||
69 | * |
||
70 | * @return LadderMemberResponse[] |
||
71 | */ |
||
72 | public function getLadder($ladderId) // todo, make enum |
||
83 | |||
84 | /** |
||
85 | * @return AchievementResponse[] |
||
86 | */ |
||
87 | public function getAchievements() |
||
102 | |||
103 | /** |
||
104 | * @param array $categories |
||
105 | * |
||
106 | * @return array |
||
107 | */ |
||
108 | private function _restructureCategories(array $categories) |
||
138 | |||
139 | /** |
||
140 | * @return RewardResponse[] |
||
141 | */ |
||
142 | public function getRewards() |
||
158 | } |
||
159 |
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.