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 | /** |
||
| 53 | * Create empty groups for direct Elimination Tree |
||
| 54 | * @param $numFighters |
||
| 55 | */ |
||
| 56 | public function pushEmptyGroupsToTree($numFighters) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Chunk Fighters into groups for fighting, and optionnaly shuffle |
||
| 66 | * @param $round |
||
| 67 | * @param $fightersByEntity |
||
| 68 | * @return mixed |
||
| 69 | */ |
||
| 70 | protected function chunkAndShuffle($round, $fightersByEntity) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Generate First Round Fights |
||
| 85 | */ |
||
| 86 | public function generateFights() |
||
| 103 | |||
| 104 | |||
| 105 | /** |
||
| 106 | * Return number of rounds for the tree based on fighter count |
||
| 107 | * @param $numFighters |
||
| 108 | * @return int |
||
| 109 | */ |
||
| 110 | public function getNumRounds($numFighters) |
||
| 114 | } |
||
| 115 |
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.