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 StartWebSocketServer extends Command |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * The name and signature of the console command. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $signature = 'websockets:serve |
||
| 27 | {--host=0.0.0.0} |
||
| 28 | {--port=6001} |
||
| 29 | {--statistics-interval= : Overwrite the statistics interval set in the config.} |
||
| 30 | {--debug : Forces the loggers to be enabled and thereby overriding the APP_DEBUG setting.} |
||
| 31 | {--test : Prepare the server, but do not start it.} |
||
| 32 | '; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * The console command description. |
||
| 36 | * |
||
| 37 | * @var string|null |
||
| 38 | */ |
||
| 39 | protected $description = 'Start the Laravel WebSocket Server'; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get the loop instance. |
||
| 43 | * |
||
| 44 | * @var \React\EventLoop\LoopInterface |
||
| 45 | */ |
||
| 46 | protected $loop; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The Pusher server instance. |
||
| 50 | * |
||
| 51 | * @var \Ratchet\Server\IoServer |
||
| 52 | */ |
||
| 53 | public $server; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Track the last restart. |
||
| 57 | * |
||
| 58 | * @var int |
||
| 59 | */ |
||
| 60 | protected $lastRestart; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Initialize the command. |
||
| 64 | * |
||
| 65 | * @return void |
||
|
|
|||
| 66 | */ |
||
| 67 | public function __construct() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Run the command. |
||
| 76 | * |
||
| 77 | * @return void |
||
| 78 | */ |
||
| 79 | public function handle() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Configure the statistics logger class. |
||
| 94 | * |
||
| 95 | * @return $this |
||
| 96 | */ |
||
| 97 | protected function configureStatisticsLogger() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Configure the HTTP logger class. |
||
| 119 | * |
||
| 120 | * @return $this |
||
| 121 | */ |
||
| 122 | View Code Duplication | protected function configureHttpLogger() |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Configure the logger for messages. |
||
| 135 | * |
||
| 136 | * @return $this |
||
| 137 | */ |
||
| 138 | View Code Duplication | protected function configureMessageLogger() |
|
| 148 | |||
| 149 | /** |
||
| 150 | * Configure the connection logger. |
||
| 151 | * |
||
| 152 | * @return $this |
||
| 153 | */ |
||
| 154 | View Code Duplication | protected function configureConnectionLogger() |
|
| 164 | |||
| 165 | /** |
||
| 166 | * Configure the Redis PubSub handler. |
||
| 167 | * |
||
| 168 | * @return $this |
||
| 169 | */ |
||
| 170 | public function configureRestartTimer() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Configure the replicators. |
||
| 185 | * |
||
| 186 | * @return void |
||
| 187 | */ |
||
| 188 | public function configurePubSub() |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Register the routes. |
||
| 210 | * |
||
| 211 | * @return $this |
||
| 212 | */ |
||
| 213 | protected function registerRoutes() |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Start the server. |
||
| 222 | * |
||
| 223 | * @return void |
||
| 224 | */ |
||
| 225 | protected function startWebSocketServer() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Build the server instance. |
||
| 245 | * |
||
| 246 | * @return void |
||
| 247 | */ |
||
| 248 | protected function buildServer() |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Get the last time the server restarted. |
||
| 263 | * |
||
| 264 | * @return int |
||
| 265 | */ |
||
| 266 | protected function getLastRestart() |
||
| 270 | } |
||
| 271 |
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.