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 $fighters |
||
| 17 | * @return Collection |
||
| 18 | */ |
||
| 19 | protected function getByeGroup($fighters) |
||
| 27 | |||
| 28 | |||
| 29 | /** |
||
| 30 | * Create empty groups for direct Elimination Tree |
||
| 31 | * @param $numFightersElim |
||
| 32 | */ |
||
| 33 | public function pushEmptyGroupsToTree($numFightersElim) |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Chunk Fighters into groups for fighting, and optionnaly shuffle |
||
| 42 | * @param $fightersByEntity |
||
| 43 | * @return Collection|null |
||
| 44 | */ |
||
| 45 | protected function chunkAndShuffle($round = null, $fightersByEntity) |
||
| 55 | |||
| 56 | |||
| 57 | /** |
||
| 58 | * Generate First Round Fights |
||
| 59 | */ |
||
| 60 | public function generateFights() |
||
| 65 | /** |
||
| 66 | * |
||
| 67 | */ |
||
| 68 | public function generateNextRoundsFights() |
||
| 77 | |||
| 78 | |||
| 79 | /** |
||
| 80 | * @param Championship $championship |
||
| 81 | * @param $fightsByRound |
||
| 82 | */ |
||
| 83 | private function updateParentFight(Championship $championship, $fightsByRound) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param $fight |
||
| 100 | * @param $parentFight |
||
| 101 | */ |
||
| 102 | private function chooseAndUpdateParentFight($fight, $parentFight) |
||
| 112 | |||
| 113 | |||
| 114 | /** |
||
| 115 | * Returns the parent field that need to be updated |
||
| 116 | * @return null|string |
||
| 117 | */ |
||
| 118 | View Code Duplication | public function getParentFighterToUpdate() |
|
| 134 | |||
| 135 | /** |
||
| 136 | * In the original fight ( child ) return the field that contains data to copy to parent |
||
| 137 | * @return null|string |
||
| 138 | */ |
||
| 139 | View Code Duplication | public function getValueToUpdate() |
|
| 152 | |||
| 153 | /** |
||
| 154 | * Check if we are able to fill the parent fight or not |
||
| 155 | * If one of the children has c1 x c2, then we must wait to fill parent |
||
| 156 | * |
||
| 157 | * @return bool |
||
| 158 | */ |
||
| 159 | View Code Duplication | public function hasDeterminedParent() |
|
| 168 | |||
| 169 | /** |
||
| 170 | * Save Groups with their parent info |
||
| 171 | * @param integer $numRounds |
||
| 172 | * @param $numFightersElim |
||
| 173 | */ |
||
| 174 | View Code Duplication | protected function pushGroups($numRounds, $numFightersElim) |
|
| 187 | |||
| 188 | /** |
||
| 189 | * Return number of rounds for the tree based on fighter count |
||
| 190 | * @param $numFighters |
||
| 191 | * @return int |
||
| 192 | */ |
||
| 193 | public function getNumRounds($numFighters){ |
||
| 196 | } |
||
| 197 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.