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 |
||
| 13 | class WidgetCurrentMap implements ListenerInterfaceExpApplication, ListenerInterfaceMpScriptMatch |
||
| 14 | { |
||
| 15 | /** @var Connection */ |
||
| 16 | protected $connection; |
||
| 17 | /** |
||
| 18 | * @var PlayerStorage |
||
| 19 | */ |
||
| 20 | private $playerStorage; |
||
| 21 | /** |
||
| 22 | * @var CurrentMapWidgetFactory |
||
| 23 | */ |
||
| 24 | private $widget; |
||
| 25 | /** |
||
| 26 | * @var Group |
||
| 27 | */ |
||
| 28 | private $players; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Debug constructor. |
||
| 32 | * |
||
| 33 | * @param Connection $connection |
||
| 34 | * @param PlayerStorage $playerStorage |
||
| 35 | * @param CurrentMapWidgetFactory $widget |
||
| 36 | */ |
||
| 37 | View Code Duplication | public function __construct( |
|
| 48 | |||
| 49 | /** |
||
| 50 | * called at eXpansion init |
||
| 51 | * |
||
| 52 | * @return void |
||
| 53 | */ |
||
| 54 | public function onApplicationInit() |
||
| 59 | |||
| 60 | /** |
||
| 61 | * called when init is done and callbacks are enabled |
||
| 62 | * |
||
| 63 | * @return void |
||
| 64 | */ |
||
| 65 | public function onApplicationReady() |
||
| 69 | |||
| 70 | /** |
||
| 71 | * called when requesting application stop |
||
| 72 | * |
||
| 73 | * @return void |
||
| 74 | */ |
||
| 75 | public function onApplicationStop() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Callback sent when the "StartMatch" section start. |
||
| 82 | * |
||
| 83 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 84 | * @param int $time Server time when the callback was sent |
||
| 85 | * |
||
| 86 | * @return void |
||
| 87 | */ |
||
| 88 | public function onStartMatchStart($count, $time) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Callback sent when the "StartMatch" section end. |
||
| 95 | * |
||
| 96 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 97 | * @param int $time Server time when the callback was sent |
||
| 98 | * |
||
| 99 | * @return void |
||
| 100 | */ |
||
| 101 | public function onStartMatchEnd($count, $time) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Callback sent when the "EndMatch" section start. |
||
| 108 | * |
||
| 109 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 110 | * @param int $time Server time when the callback was sent |
||
| 111 | * |
||
| 112 | * @return void |
||
| 113 | */ |
||
| 114 | public function onEndMatchStart($count, $time) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Callback sent when the "EndMatch" section end. |
||
| 121 | * |
||
| 122 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 123 | * @param int $time Server time when the callback was sent |
||
| 124 | * |
||
| 125 | * @return void |
||
| 126 | */ |
||
| 127 | public function onEndMatchEnd($count, $time) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Callback sent when the "StartTurn" section start. |
||
| 134 | * |
||
| 135 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 136 | * @param int $time Server time when the callback was sent |
||
| 137 | * |
||
| 138 | * @return void |
||
| 139 | */ |
||
| 140 | public function onStartTurnStart($count, $time) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Callback sent when the "StartTurn" section end. |
||
| 147 | * |
||
| 148 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 149 | * @param int $time Server time when the callback was sent |
||
| 150 | * |
||
| 151 | * @return void |
||
| 152 | */ |
||
| 153 | public function onStartTurnEnd($count, $time) |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Callback sent when the "EndMatch" section start. |
||
| 160 | * |
||
| 161 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 162 | * @param int $time Server time when the callback was sent |
||
| 163 | * |
||
| 164 | * @return void |
||
| 165 | */ |
||
| 166 | public function onEndTurnStart($count, $time) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Callback sent when the "EndMatch" section end. |
||
| 173 | * |
||
| 174 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 175 | * @param int $time Server time when the callback was sent |
||
| 176 | * |
||
| 177 | * @return void |
||
| 178 | */ |
||
| 179 | public function onEndTurnEnd($count, $time) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Callback sent when the "StartRound" section start. |
||
| 186 | * |
||
| 187 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 188 | * @param int $time Server time when the callback was sent |
||
| 189 | * |
||
| 190 | * @return void |
||
| 191 | */ |
||
| 192 | public function onStartRoundStart($count, $time) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Callback sent when the "StartRound" section end. |
||
| 199 | * |
||
| 200 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 201 | * @param int $time Server time when the callback was sent |
||
| 202 | * |
||
| 203 | * @return void |
||
| 204 | */ |
||
| 205 | public function onStartRoundEnd($count, $time) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Callback sent when the "EndMatch" section start. |
||
| 212 | * |
||
| 213 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 214 | * @param int $time Server time when the callback was sent |
||
| 215 | * |
||
| 216 | * @return void |
||
| 217 | */ |
||
| 218 | public function onEndRoundStart($count, $time) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Callback sent when the "EndMatch" section end. |
||
| 224 | * |
||
| 225 | * @param int $count Each time this section is played, this number is incremented by one |
||
| 226 | * @param int $time Server time when the callback was sent |
||
| 227 | * |
||
| 228 | * @return void |
||
| 229 | */ |
||
| 230 | public function onEndRoundEnd($count, $time) |
||
| 234 | } |
||
| 235 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.