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 |
||
| 19 | class BestCheckpoints implements StatusAwarePluginInterface, RecordsDataListener,ListenerInterfaceMpLegacyMap |
||
|
|
|||
| 20 | { |
||
| 21 | /** @var Connection */ |
||
| 22 | protected $connection; |
||
| 23 | /** |
||
| 24 | * @var PlayerStorage |
||
| 25 | */ |
||
| 26 | private $playerStorage; |
||
| 27 | /** |
||
| 28 | * @var BestCheckpointsWidgetFactory |
||
| 29 | */ |
||
| 30 | private $widget; |
||
| 31 | /** |
||
| 32 | * @var Group |
||
| 33 | */ |
||
| 34 | private $players; |
||
| 35 | /** |
||
| 36 | * @var UpdaterWidgetFactory |
||
| 37 | */ |
||
| 38 | private $updater; |
||
| 39 | /** |
||
| 40 | * @var Group |
||
| 41 | */ |
||
| 42 | private $allPlayers; |
||
| 43 | |||
| 44 | |||
| 45 | /** |
||
| 46 | * Debug constructor. |
||
| 47 | * |
||
| 48 | * @param Connection $connection |
||
| 49 | * @param PlayerStorage $playerStorage |
||
| 50 | * @param BestCheckPointsWidgetFactory $widget |
||
| 51 | * @param UpdaterWidgetFactory $updater |
||
| 52 | * @param Group $players |
||
| 53 | * @param Group $allPlayers |
||
| 54 | */ |
||
| 55 | public function __construct( |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Set the status of the plugin |
||
| 73 | * |
||
| 74 | * @param boolean $status |
||
| 75 | * |
||
| 76 | * @return void |
||
| 77 | */ |
||
| 78 | public function setStatus($status) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Called when local records are loaded. |
||
| 91 | * |
||
| 92 | * @param Record[] $records |
||
| 93 | */ |
||
| 94 | public function onLocalRecordsLoaded($records) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Called when a player finishes map for the very first time (basically first record). |
||
| 106 | * |
||
| 107 | * @param Record $record |
||
| 108 | * @param Record[] $records |
||
| 109 | * @param $position |
||
| 110 | */ |
||
| 111 | public function onLocalRecordsFirstRecord(Record $record, $records, $position) |
||
| 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) |
||
| 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) |
|
| 146 | |||
| 147 | /** |
||
| 148 | * Called when a player finishes map with better time but keeps same position. |
||
| 149 | * |
||
| 150 | * @param Record $record |
||
| 151 | * @param Record $oldRecord |
||
| 152 | * @param Record[] $records |
||
| 153 | * @param $position |
||
| 154 | */ |
||
| 155 | View Code Duplication | public function onLocalRecordsSamePosition(Record $record, Record $oldRecord, $records, $position) |
|
| 162 | |||
| 163 | |||
| 164 | /** |
||
| 165 | * @param Map $map |
||
| 166 | * |
||
| 167 | * @return void |
||
| 168 | */ |
||
| 169 | public function onBeginMap(Map $map) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param Map $map |
||
| 176 | * |
||
| 177 | * @return void |
||
| 178 | */ |
||
| 179 | public function onEndMap(Map $map) |
||
| 183 | } |
||
| 184 |