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 |
||
11 | View Code Duplication | class SingleEliminationTeamTreeGen extends SingleEliminationTreeGen |
|
|
|||
12 | { |
||
13 | /** |
||
14 | * get Fighter by Id. |
||
15 | * |
||
16 | * @return Team |
||
17 | */ |
||
18 | protected function getFighter($teamId) |
||
22 | |||
23 | /** |
||
24 | * Fighter is the name for competitor or team, depending on the case. |
||
25 | * |
||
26 | * @return Collection |
||
27 | */ |
||
28 | protected function getFighters() |
||
32 | |||
33 | /** |
||
34 | * @param FightersGroup $group |
||
35 | * @param $fighters |
||
36 | * |
||
37 | * @return FightersGroup |
||
38 | */ |
||
39 | public function syncGroup(FightersGroup $group, $fighters) |
||
44 | |||
45 | protected function createByeFighter() |
||
49 | |||
50 | protected function addFighterToGroup(FightersGroup $group, $team) |
||
54 | /** |
||
55 | * Chunk Fighters into groups for fighting, and optionnaly shuffle. |
||
56 | * |
||
57 | * @param $fightersByEntity |
||
58 | * |
||
59 | * @return Collection|null |
||
60 | */ |
||
61 | protected function chunkAndShuffle(Collection $fightersByEntity) |
||
75 | |||
76 | |||
77 | /** |
||
78 | * @param FightersGroup $group |
||
79 | * @param Fight $fight |
||
80 | * @param $oldTeams |
||
81 | */ |
||
82 | protected function updateGroupFighters(FightersGroup $group, Fight $fight, $oldTeams) |
||
105 | } |
||
106 |
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.