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 |
||
| 16 | class BestCheckpoints implements ListenerInterfaceExpApplication, RecordsDataListener, ListenerInterfaceMpScriptMatch |
||
| 17 | { |
||
| 18 | /** @var Connection */ |
||
| 19 | protected $connection; |
||
| 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 | private $justStarted = true; |
||
|
|
|||
| 42 | |||
| 43 | /** |
||
| 44 | * Debug constructor. |
||
| 45 | * |
||
| 46 | * @param Connection $connection |
||
| 47 | * @param PlayerStorage $playerStorage |
||
| 48 | * @param BestCheckPointsWidgetFactory $widget |
||
| 49 | * @param UpdaterWidgetFactory $updater |
||
| 50 | * @param Group $players |
||
| 51 | * @param Group $allPlayers |
||
| 52 | */ |
||
| 53 | public function __construct( |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Set the status of the plugin |
||
| 71 | * |
||
| 72 | * @param boolean $status |
||
| 73 | * |
||
| 74 | * @return null |
||
| 75 | */ |
||
| 76 | public function setStatus($status) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * called at eXpansion init |
||
| 83 | * |
||
| 84 | * @return void |
||
| 85 | */ |
||
| 86 | public function onApplicationInit() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * called when init is done and callbacks are enabled |
||
| 94 | * |
||
| 95 | * @return void |
||
| 96 | */ |
||
| 97 | public function onApplicationReady() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * called when requesting application stop |
||
| 105 | * |
||
| 106 | * @return void |
||
| 107 | */ |
||
| 108 | public function onApplicationStop() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Called when local records are loaded. |
||
| 115 | * |
||
| 116 | * @param Record[] $records |
||
| 117 | */ |
||
| 118 | public function onLocalRecordsLoaded($records) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Called when a player finishes map for the very first time (basically first record). |
||
| 130 | * |
||
| 131 | * @param Record $record |
||
| 132 | * @param Record[] $records |
||
| 133 | * @param $position |
||
| 134 | */ |
||
| 135 | public function onLocalRecordsFirstRecord(Record $record, $records, $position) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Called when a player finishes map and does same time as before. |
||
| 144 | * |
||
| 145 | * @param Record $record |
||
| 146 | * @param Record $oldRecord |
||
| 147 | * @param Record[] $records |
||
| 148 | */ |
||
| 149 | public function onLocalRecordsSameScore(Record $record, Record $oldRecord, $records) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Called when a player finishes map with better time and has better position. |
||
| 156 | * |
||
| 157 | * @param Record $record |
||
| 158 | * @param Record $oldRecord |
||
| 159 | * @param Record[] $records |
||
| 160 | * @param int $position |
||
| 161 | * @param int $oldPosition |
||
| 162 | */ |
||
| 163 | View Code Duplication | public function onLocalRecordsBetterPosition(Record $record, Record $oldRecord, $records, $position, $oldPosition) |
|
| 170 | |||
| 171 | /** |
||
| 172 | * Called when a player finishes map with better time but keeps same position. |
||
| 173 | * |
||
| 174 | * @param Record $record |
||
| 175 | * @param Record $oldRecord |
||
| 176 | * @param Record[] $records |
||
| 177 | * @param $position |
||
| 178 | */ |
||
| 179 | View Code Duplication | public function onLocalRecordsSamePosition(Record $record, Record $oldRecord, $records, $position) |
|
| 186 | |||
| 187 | /** |
||
| 188 | * Callback sent when the "StartMatch" section start. |
||
| 189 | * |
||
| 190 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 191 | * @param int $time Server time when the callback was sent |
||
| 192 | * |
||
| 193 | * @return void |
||
| 194 | */ |
||
| 195 | public function onStartMatchStart($count, $time) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Callback sent when the "StartMatch" section end. |
||
| 202 | * |
||
| 203 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 204 | * @param int $time Server time when the callback was sent |
||
| 205 | * |
||
| 206 | * @return void |
||
| 207 | */ |
||
| 208 | public function onStartMatchEnd($count, $time) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Callback sent when the "EndMatch" section start. |
||
| 215 | * |
||
| 216 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 217 | * @param int $time Server time when the callback was sent |
||
| 218 | * |
||
| 219 | * @return void |
||
| 220 | */ |
||
| 221 | public function onEndMatchStart($count, $time) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Callback sent when the "EndMatch" section end. |
||
| 228 | * |
||
| 229 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 230 | * @param int $time Server time when the callback was sent |
||
| 231 | * |
||
| 232 | * @return void |
||
| 233 | */ |
||
| 234 | public function onEndMatchEnd($count, $time) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Callback sent when the "StartTurn" section start. |
||
| 241 | * |
||
| 242 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 243 | * @param int $time Server time when the callback was sent |
||
| 244 | * |
||
| 245 | * @return void |
||
| 246 | */ |
||
| 247 | public function onStartTurnStart($count, $time) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Callback sent when the "StartTurn" section end. |
||
| 254 | * |
||
| 255 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 256 | * @param int $time Server time when the callback was sent |
||
| 257 | * |
||
| 258 | * @return void |
||
| 259 | */ |
||
| 260 | public function onStartTurnEnd($count, $time) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Callback sent when the "EndMatch" section start. |
||
| 267 | * |
||
| 268 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 269 | * @param int $time Server time when the callback was sent |
||
| 270 | * |
||
| 271 | * @return void |
||
| 272 | */ |
||
| 273 | public function onEndTurnStart($count, $time) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Callback sent when the "EndMatch" section end. |
||
| 280 | * |
||
| 281 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 282 | * @param int $time Server time when the callback was sent |
||
| 283 | * |
||
| 284 | * @return void |
||
| 285 | */ |
||
| 286 | public function onEndTurnEnd($count, $time) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Callback sent when the "StartRound" section start. |
||
| 293 | * |
||
| 294 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 295 | * @param int $time Server time when the callback was sent |
||
| 296 | * |
||
| 297 | * @return void |
||
| 298 | */ |
||
| 299 | public function onStartRoundStart($count, $time) |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Callback sent when the "StartRound" section end. |
||
| 306 | * |
||
| 307 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 308 | * @param int $time Server time when the callback was sent |
||
| 309 | * |
||
| 310 | * @return void |
||
| 311 | */ |
||
| 312 | public function onStartRoundEnd($count, $time) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Callback sent when the "EndMatch" section start. |
||
| 319 | * |
||
| 320 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 321 | * @param int $time Server time when the callback was sent |
||
| 322 | * |
||
| 323 | * @return void |
||
| 324 | */ |
||
| 325 | public function onEndRoundStart($count, $time) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Callback sent when the "EndMatch" section end. |
||
| 332 | * |
||
| 333 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 334 | * @param int $time Server time when the callback was sent |
||
| 335 | * |
||
| 336 | * @return void |
||
| 337 | */ |
||
| 338 | public function onEndRoundEnd($count, $time) |
||
| 342 | } |
||
| 343 |
This check marks private properties in classes that are never used. Those properties can be removed.