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 |
||
13 | View Code Duplication | class ChampionMasteryApi extends BaseApi |
|
|
|||
14 | { |
||
15 | const API_URL_CHAMPION_MASTERY_BY_ID = '/lol/champion-mastery/v3/champion-masteries/by-summoner/{summonerId}'; |
||
16 | const API_URL_CHAMPION_MASTERY_BY_CHAMPION_ID = '/lol/champion-mastery/v3/champion-masteries/by-summoner/{summonerId}/by-champion/{championId}'; |
||
17 | const API_URL_CHAMPION_MASTERY_SCORE = '/lol/champion-mastery/v3/scores/by-summoner/{summonerId}'; |
||
18 | |||
19 | /** |
||
20 | * Get all champion mastery entries sorted by number of champion points descending, |
||
21 | * |
||
22 | * @param int $summonerId |
||
23 | * |
||
24 | * @return ApiResult |
||
25 | */ |
||
26 | public function getChampionsMasteries($summonerId) |
||
32 | |||
33 | 1 | /** |
|
34 | * @param int $summonerId |
||
35 | * @param int $championId |
||
36 | * |
||
37 | * @return ApiResult |
||
38 | */ |
||
39 | public function getChampionMastery($summonerId, $championId) |
||
46 | |||
47 | 1 | /** |
|
48 | * Get a player's total champion mastery score, which is the sum of individual champion mastery levels |
||
49 | * |
||
50 | * @param int $summonerId |
||
51 | * |
||
52 | * @return ApiResult |
||
53 | */ |
||
54 | public function getChampionsMasteriesScore($summonerId) |
||
60 | } |
||
61 |
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.