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 StartServer extends Command |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * The name and signature of the console command. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $signature = 'websockets:serve |
||
| 24 | {--host=0.0.0.0} |
||
| 25 | {--port=6001} |
||
| 26 | {--disable-statistics : Disable the statistics tracking.} |
||
| 27 | {--statistics-interval= : The amount of seconds to tick between statistics saving.} |
||
| 28 | {--debug : Forces the loggers to be enabled and thereby overriding the APP_DEBUG setting.} |
||
| 29 | {--loop : Programatically inject the loop.} |
||
| 30 | '; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The console command description. |
||
| 34 | * |
||
| 35 | * @var string|null |
||
| 36 | */ |
||
| 37 | protected $description = 'Start the LaravelWebSockets server.'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Get the loop instance. |
||
| 41 | * |
||
| 42 | * @var \React\EventLoop\LoopInterface |
||
| 43 | */ |
||
| 44 | protected $loop; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * The Pusher server instance. |
||
| 48 | * |
||
| 49 | * @var \Ratchet\Server\IoServer |
||
| 50 | */ |
||
| 51 | public $server; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Initialize the command. |
||
| 55 | * |
||
| 56 | * @return void |
||
|
|
|||
| 57 | */ |
||
| 58 | public function __construct() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Run the command. |
||
| 67 | * |
||
| 68 | * @return void |
||
| 69 | */ |
||
| 70 | public function handle() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Configure the loggers used for the console. |
||
| 91 | * |
||
| 92 | * @return void |
||
| 93 | */ |
||
| 94 | protected function configureLoggers() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Register the managers that are not resolved |
||
| 103 | * in the package service provider. |
||
| 104 | * |
||
| 105 | * @return void |
||
| 106 | */ |
||
| 107 | protected function configureManagers() |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Register the Statistics Collectors that |
||
| 120 | * are not resolved in the package service provider. |
||
| 121 | * |
||
| 122 | * @return void |
||
| 123 | */ |
||
| 124 | protected function configureStatistics() |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Configure the restart timer. |
||
| 139 | * |
||
| 140 | * @return void |
||
| 141 | */ |
||
| 142 | public function configureRestartTimer() |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Register the routes for the server. |
||
| 155 | * |
||
| 156 | * @return void |
||
| 157 | */ |
||
| 158 | protected function configureRoutes() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Configure the PCNTL signals for soft shutdown. |
||
| 165 | * |
||
| 166 | * @return void |
||
| 167 | */ |
||
| 168 | protected function configurePcntlSignal() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Configure the tracker that will delete |
||
| 190 | * from the store the connections that. |
||
| 191 | * |
||
| 192 | * @return void |
||
| 193 | */ |
||
| 194 | protected function configurePongTracker() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Configure the HTTP logger class. |
||
| 205 | * |
||
| 206 | * @return void |
||
| 207 | */ |
||
| 208 | View Code Duplication | protected function configureHttpLogger() |
|
| 216 | |||
| 217 | /** |
||
| 218 | * Configure the logger for messages. |
||
| 219 | * |
||
| 220 | * @return void |
||
| 221 | */ |
||
| 222 | View Code Duplication | protected function configureMessageLogger() |
|
| 230 | |||
| 231 | /** |
||
| 232 | * Configure the connection logger. |
||
| 233 | * |
||
| 234 | * @return void |
||
| 235 | */ |
||
| 236 | protected function configureConnectionLogger() |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Start the server. |
||
| 247 | * |
||
| 248 | * @return void |
||
| 249 | */ |
||
| 250 | protected function startServer() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Build the server instance. |
||
| 261 | * |
||
| 262 | * @return void |
||
| 263 | */ |
||
| 264 | protected function buildServer() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Get the last time the server restarted. |
||
| 283 | * |
||
| 284 | * @return int |
||
| 285 | */ |
||
| 286 | protected function getLastRestart() |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Trigger a soft shutdown for the process. |
||
| 295 | * |
||
| 296 | * @return void |
||
| 297 | */ |
||
| 298 | protected function triggerSoftShutdown() |
||
| 317 | } |
||
| 318 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.