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 |
||
17 | class StartServer extends Command |
||
18 | { |
||
19 | /** |
||
20 | * The name and signature of the console command. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $signature = 'websockets:serve |
||
25 | {--host=0.0.0.0} |
||
26 | {--port=6001} |
||
27 | {--disable-statistics : Disable the statistics tracking.} |
||
28 | {--statistics-interval= : The amount of seconds to tick between statistics saving.} |
||
29 | {--debug : Forces the loggers to be enabled and thereby overriding the APP_DEBUG setting.} |
||
30 | {--test : Prepare the server, but do not start it.} |
||
31 | '; |
||
32 | |||
33 | /** |
||
34 | * The console command description. |
||
35 | * |
||
36 | * @var string|null |
||
37 | */ |
||
38 | protected $description = 'Start the LaravelWebSockets server.'; |
||
39 | |||
40 | /** |
||
41 | * Get the loop instance. |
||
42 | * |
||
43 | * @var \React\EventLoop\LoopInterface |
||
44 | */ |
||
45 | protected $loop; |
||
46 | |||
47 | /** |
||
48 | * The Pusher server instance. |
||
49 | * |
||
50 | * @var \Ratchet\Server\IoServer |
||
51 | */ |
||
52 | public $server; |
||
53 | |||
54 | /** |
||
55 | * Initialize the command. |
||
56 | * |
||
57 | * @return void |
||
|
|||
58 | */ |
||
59 | public function __construct() |
||
65 | |||
66 | /** |
||
67 | * Run the command. |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | public function handle() |
||
85 | |||
86 | /** |
||
87 | * Configure the loggers used for the console. |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | protected function configureLoggers() |
||
97 | |||
98 | /** |
||
99 | * Register the managers that are not resolved |
||
100 | * in the package service provider. |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | protected function configureManagers() |
||
114 | |||
115 | /** |
||
116 | * Register the Statistics Collectors that |
||
117 | * are not resolved in the package service provider. |
||
118 | * |
||
119 | * @return void |
||
120 | */ |
||
121 | protected function configureStatistics() |
||
147 | |||
148 | /** |
||
149 | * Configure the restart timer. |
||
150 | * |
||
151 | * @return void |
||
152 | */ |
||
153 | public function configureRestartTimer() |
||
163 | |||
164 | /** |
||
165 | * Register the routes for the server. |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | protected function configureRoutes() |
||
173 | |||
174 | /** |
||
175 | * Configure the HTTP logger class. |
||
176 | * |
||
177 | * @return void |
||
178 | */ |
||
179 | View Code Duplication | protected function configureHttpLogger() |
|
187 | |||
188 | /** |
||
189 | * Configure the logger for messages. |
||
190 | * |
||
191 | * @return void |
||
192 | */ |
||
193 | View Code Duplication | protected function configureMessageLogger() |
|
201 | |||
202 | /** |
||
203 | * Configure the connection logger. |
||
204 | * |
||
205 | * @return void |
||
206 | */ |
||
207 | protected function configureConnectionLogger() |
||
215 | |||
216 | /** |
||
217 | * Start the server. |
||
218 | * |
||
219 | * @return void |
||
220 | */ |
||
221 | protected function startServer() |
||
237 | |||
238 | /** |
||
239 | * Build the server instance. |
||
240 | * |
||
241 | * @return void |
||
242 | */ |
||
243 | protected function buildServer() |
||
255 | |||
256 | /** |
||
257 | * Get the last time the server restarted. |
||
258 | * |
||
259 | * @return int |
||
260 | */ |
||
261 | protected function getLastRestart() |
||
267 | } |
||
268 |
Adding a
@return
annotation 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.