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 |
||
7 | class PreliminaryFight extends Fight |
||
8 | { |
||
9 | View Code Duplication | public function __construct(Fight $fight = null) |
|
20 | |||
21 | /** |
||
22 | * Save all fights. |
||
23 | * |
||
24 | * @param Collection $groups |
||
25 | * @param int $numGroup |
||
26 | */ |
||
27 | public static function saveFights(Collection $groups, $numGroup = 1) |
||
56 | |||
57 | |||
58 | /** |
||
59 | * Save a Fight. |
||
60 | * |
||
61 | * @param Collection $group |
||
62 | * @param int $numGroup |
||
63 | * @param int $order |
||
64 | */ |
||
65 | public static function saveFight2(FightersGroup $group, $numGroup = 1, $order = 1) // TODO Rename it, bad name |
||
90 | |||
91 | /** |
||
92 | * @param $group |
||
93 | * @param $competitor1 |
||
94 | * @param $competitor2 |
||
95 | * @param $order |
||
96 | * |
||
97 | * @return mixed |
||
98 | */ |
||
99 | private static function saveFight($group, $competitor1, $competitor2, $order) |
||
110 | } |
||
111 |
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.