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() |
||
86 | |||
87 | /** |
||
88 | * Configure the loggers used for the console. |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | protected function configureLoggers() |
||
98 | |||
99 | /** |
||
100 | * Register the managers that are not resolved |
||
101 | * in the package service provider. |
||
102 | * |
||
103 | * @return void |
||
104 | */ |
||
105 | protected function configureManagers() |
||
115 | |||
116 | /** |
||
117 | * Register the Statistics Collectors that |
||
118 | * are not resolved in the package service provider. |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | protected function configureStatistics() |
||
134 | |||
135 | /** |
||
136 | * Configure the restart timer. |
||
137 | * |
||
138 | * @return void |
||
139 | */ |
||
140 | public function configureRestartTimer() |
||
150 | |||
151 | /** |
||
152 | * Register the routes for the server. |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | protected function configureRoutes() |
||
160 | |||
161 | /** |
||
162 | * Configure the PCNTL signals for soft shutdown. |
||
163 | * |
||
164 | * @return void |
||
165 | */ |
||
166 | protected function configurePcntlSignal() |
||
185 | |||
186 | /** |
||
187 | * Configure the HTTP logger class. |
||
188 | * |
||
189 | * @return void |
||
190 | */ |
||
191 | View Code Duplication | protected function configureHttpLogger() |
|
199 | |||
200 | /** |
||
201 | * Configure the logger for messages. |
||
202 | * |
||
203 | * @return void |
||
204 | */ |
||
205 | View Code Duplication | protected function configureMessageLogger() |
|
213 | |||
214 | /** |
||
215 | * Configure the connection logger. |
||
216 | * |
||
217 | * @return void |
||
218 | */ |
||
219 | protected function configureConnectionLogger() |
||
227 | |||
228 | /** |
||
229 | * Start the server. |
||
230 | * |
||
231 | * @return void |
||
232 | */ |
||
233 | protected function startServer() |
||
241 | |||
242 | /** |
||
243 | * Build the server instance. |
||
244 | * |
||
245 | * @return void |
||
246 | */ |
||
247 | protected function buildServer() |
||
263 | |||
264 | /** |
||
265 | * Get the last time the server restarted. |
||
266 | * |
||
267 | * @return int |
||
268 | */ |
||
269 | protected function getLastRestart() |
||
275 | |||
276 | /** |
||
277 | * Trigger a soft shutdown for the process. |
||
278 | * |
||
279 | * @return void |
||
280 | */ |
||
281 | protected function triggerSoftShutdown() |
||
300 | } |
||
301 |
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.