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 |
||
| 18 | class BestCheckpoints implements StatusAwarePluginInterface, RecordsDataListener, ListenerInterfaceMpLegacyMap |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var PlayerStorage |
||
| 22 | */ |
||
| 23 | private $playerStorage; |
||
| 24 | /** |
||
| 25 | * @var BestCheckpointsWidgetFactory |
||
| 26 | */ |
||
| 27 | private $widget; |
||
| 28 | /** |
||
| 29 | * @var Group |
||
| 30 | */ |
||
| 31 | private $players; |
||
| 32 | /** |
||
| 33 | * @var UpdaterWidgetFactory |
||
| 34 | */ |
||
| 35 | private $updater; |
||
| 36 | /** |
||
| 37 | * @var Group |
||
| 38 | */ |
||
| 39 | private $allPlayers; |
||
| 40 | |||
| 41 | |||
| 42 | /** |
||
| 43 | * BestCheckpoints constructor. |
||
| 44 | * |
||
| 45 | * @param Factory $factory |
||
|
|
|||
| 46 | * @param PlayerStorage $playerStorage |
||
| 47 | * @param BestCheckpointsWidgetFactory $widget |
||
| 48 | * @param UpdaterWidgetFactory $updater |
||
| 49 | * @param Group $players |
||
| 50 | * @param Group $allPlayers |
||
| 51 | */ |
||
| 52 | View Code Duplication | public function __construct( |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Set the status of the plugin |
||
| 68 | * |
||
| 69 | * @param boolean $status |
||
| 70 | * |
||
| 71 | * @return void |
||
| 72 | */ |
||
| 73 | public function setStatus($status) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Called when local records are loaded. |
||
| 86 | * |
||
| 87 | * @param Record[] $records |
||
| 88 | */ |
||
| 89 | public function onLocalRecordsLoaded($records, BaseRecords $baseRecords) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Called when a player finishes map for the very first time (basically first record). |
||
| 104 | * |
||
| 105 | * @param Record $record |
||
| 106 | * @param Record[] $records |
||
| 107 | * @param $position |
||
| 108 | */ |
||
| 109 | public function onLocalRecordsFirstRecord(Record $record, $records, $position, BaseRecords $baseRecords) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Called when a player finishes map and does same time as before. |
||
| 120 | * |
||
| 121 | * @param Record $record |
||
| 122 | * @param Record $oldRecord |
||
| 123 | * @param Record[] $records |
||
| 124 | */ |
||
| 125 | public function onLocalRecordsSameScore(Record $record, Record $oldRecord, $records, BaseRecords $baseRecords) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Called when a player finishes map with better time and has better position. |
||
| 132 | * |
||
| 133 | * @param Record $record |
||
| 134 | * @param Record $oldRecord |
||
| 135 | * @param Record[] $records |
||
| 136 | * @param int $position |
||
| 137 | * @param int $oldPosition |
||
| 138 | */ |
||
| 139 | View Code Duplication | public function onLocalRecordsBetterPosition(Record $record, Record $oldRecord, $records, $position, $oldPosition, BaseRecords $baseRecords) |
|
| 149 | |||
| 150 | /** |
||
| 151 | * Called when a player finishes map with better time but keeps same position. |
||
| 152 | * |
||
| 153 | * @param Record $record |
||
| 154 | * @param Record $oldRecord |
||
| 155 | * @param Record[] $records |
||
| 156 | * @param $position |
||
| 157 | */ |
||
| 158 | View Code Duplication | public function onLocalRecordsSamePosition(Record $record, Record $oldRecord, $records, $position, BaseRecords $baseRecords) |
|
| 168 | |||
| 169 | /** |
||
| 170 | * Check if we can use the data for this plugin. |
||
| 171 | * |
||
| 172 | * @param BaseRecords $baseRecords |
||
| 173 | * |
||
| 174 | * @return bool |
||
| 175 | */ |
||
| 176 | protected function checkRecordPlugin(BaseRecords $baseRecords) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @param Map $map |
||
| 183 | * |
||
| 184 | * @return void |
||
| 185 | */ |
||
| 186 | public function onBeginMap(Map $map) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param Map $map |
||
| 193 | * |
||
| 194 | * @return void |
||
| 195 | */ |
||
| 196 | public function onEndMap(Map $map) |
||
| 200 | } |
||
| 201 |
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.