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 |
||
| 12 | class PlayOffTreeGen extends TreeGen |
||
| 13 | { |
||
| 14 | |||
| 15 | |||
| 16 | /** |
||
| 17 | * Calculate the Byes need to fill the Championship Tree. |
||
| 18 | * @param Championship $championship |
||
|
|
|||
| 19 | * @param $fighters |
||
| 20 | * @return Collection |
||
| 21 | */ |
||
| 22 | protected function getByeGroup($fighters) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Save Groups with their parent info |
||
| 34 | * @param integer $numRounds |
||
| 35 | * @param $numFightersElim |
||
| 36 | */ |
||
| 37 | View Code Duplication | protected function pushGroups($numRounds, $numFightersElim) |
|
| 51 | /** |
||
| 52 | * Create empty groups for direct Elimination Tree |
||
| 53 | * @param $numFighters |
||
| 54 | */ |
||
| 55 | public function pushEmptyGroupsToTree($numFighters) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Chunk Fighters into groups for fighting, and optionnaly shuffle |
||
| 65 | * @param $round |
||
| 66 | * @param $fightersByEntity |
||
| 67 | * @return mixed |
||
| 68 | */ |
||
| 69 | protected function chunkAndShuffle($round, $fightersByEntity) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Generate First Round Fights |
||
| 84 | */ |
||
| 85 | public function generateFights() |
||
| 99 | |||
| 100 | |||
| 101 | /** |
||
| 102 | * Generate Fights for next rounds |
||
| 103 | */ |
||
| 104 | public function generateNextRoundsFights() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Return number of rounds for the tree based on fighter count |
||
| 112 | * @param $numFighters |
||
| 113 | * @return int |
||
| 114 | */ |
||
| 115 | public function getNumRounds($numFighters){ |
||
| 118 | } |
||
| 119 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.