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 | * Save Groups with their parent info |
||
| 69 | * @param integer $numRounds |
||
| 70 | * @param $numFightersElim |
||
| 71 | */ |
||
| 72 | View Code Duplication | protected function pushGroups($numRounds, $numFightersElim) |
|
| 85 | |||
| 86 | /** |
||
| 87 | * Return number of rounds for the tree based on fighter count |
||
| 88 | * @param $numFighters |
||
| 89 | * @return int |
||
| 90 | */ |
||
| 91 | public function getNumRounds($numFighters) |
||
| 95 | } |
||
| 96 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.