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 Maps implements MatchDataListenerInterface, MapDataListenerInterface, StatusAwarePluginInterface |
||
| 17 | { |
||
| 18 | /** @var Connection */ |
||
| 19 | protected $connection; |
||
| 20 | |||
| 21 | /** @var Console */ |
||
| 22 | protected $console; |
||
| 23 | |||
| 24 | /** @var AdminGroups */ |
||
| 25 | protected $adminGroups; |
||
| 26 | |||
| 27 | /** @var bool */ |
||
| 28 | protected $enabled = true; |
||
| 29 | |||
| 30 | /** @var MapStorage */ |
||
| 31 | protected $mapStorage; |
||
| 32 | |||
| 33 | /** @var ChatNotification */ |
||
| 34 | protected $chatNotification; |
||
| 35 | |||
| 36 | View Code Duplication | function __construct( |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Set the status of the plugin |
||
| 52 | * |
||
| 53 | * @param boolean $status |
||
| 54 | * |
||
| 55 | * @return void |
||
| 56 | */ |
||
| 57 | public function setStatus($status) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | public function getMaps() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param \Maniaplanet\DedicatedServer\Structures\Map[] $oldMaps |
||
| 74 | * @param string $currentMapUid |
||
| 75 | * @param string $nextMapUid |
||
| 76 | * @param bool $isListModified |
||
| 77 | * @return mixed|void |
||
| 78 | */ |
||
| 79 | public function onMapListModified($oldMaps, $currentMapUid, $nextMapUid, $isListModified) |
||
| 83 | |||
| 84 | public function onExpansionMapChange($currentMap, $previousMap) |
||
| 88 | |||
| 89 | public function onExpansionNextMapChange($nextMap, $previousNextMap) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param Map $map |
||
| 96 | * |
||
| 97 | * @return mixed |
||
| 98 | */ |
||
| 99 | public function onBeginMap(Map $map) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @param Map $map |
||
| 106 | * |
||
| 107 | * @return mixed |
||
| 108 | */ |
||
| 109 | public function onEndMap(Map $map) |
||
| 113 | } |
||
| 114 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.