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 | class DirectEliminationTreeGen extends TreeGen |
||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Calculate the Byes need to fill the Championship Tree. |
||
| 16 | * @param Championship $championship |
||
| 17 | * @param $fighters |
||
| 18 | * @return Collection |
||
| 19 | */ |
||
| 20 | protected function getByeGroup(Championship $championship, $fighters) |
||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * Create empty groups for direct Elimination Tree |
||
| 32 | * @param $numFightersElim |
||
| 33 | */ |
||
| 34 | public function pushEmptyGroupsToTree($numFightersElim) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Chunk Fighters into groups for fighting, and optionnaly shuffle |
||
| 43 | * @param $fightersByEntity |
||
| 44 | * @return Collection|null |
||
| 45 | */ |
||
| 46 | protected function chunkAndShuffle($round = null, $fightersByEntity) |
||
| 56 | |||
| 57 | |||
| 58 | /** |
||
| 59 | * Generate First Round Fights |
||
| 60 | */ |
||
| 61 | public function generateFights() |
||
| 67 | /** |
||
| 68 | * |
||
| 69 | */ |
||
| 70 | public function generateNextRoundsFights() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @param Championship $championship |
||
| 83 | * @param $fightsByRound |
||
| 84 | */ |
||
| 85 | private function updateParentFight(Championship $championship, $fightsByRound) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @param $fight |
||
| 102 | * @param $parentFight |
||
| 103 | */ |
||
| 104 | private function chooseAndUpdateParentFight($fight, $parentFight) |
||
| 114 | |||
| 115 | |||
| 116 | /** |
||
| 117 | * Returns the parent field that need to be updated |
||
| 118 | * @return null|string |
||
| 119 | */ |
||
| 120 | View Code Duplication | public function getParentFighterToUpdate() |
|
| 136 | |||
| 137 | /** |
||
| 138 | * In the original fight ( child ) return the field that contains data to copy to parent |
||
| 139 | * @return null|string |
||
| 140 | */ |
||
| 141 | View Code Duplication | public function getValueToUpdate() |
|
| 154 | |||
| 155 | /** |
||
| 156 | * Check if we are able to fill the parent fight or not |
||
| 157 | * If one of the children has c1 x c2, then we must wait to fill parent |
||
| 158 | * |
||
| 159 | * @return bool |
||
| 160 | */ |
||
| 161 | View Code Duplication | public function hasDeterminedParent() |
|
| 170 | } |
||
| 171 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.