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 |
||
21 | class StartWebSocketServer extends Command |
||
22 | { |
||
23 | /** |
||
24 | * The name and signature of the console command. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $signature = 'websockets:serve |
||
29 | {--host=0.0.0.0} |
||
30 | {--port=6001} |
||
31 | {--statistics-interval= : Overwrite the statistics interval set in the config.} |
||
32 | {--debug : Forces the loggers to be enabled and thereby overriding the APP_DEBUG setting.} |
||
33 | {--test : Prepare the server, but do not start it.} |
||
34 | '; |
||
35 | |||
36 | /** |
||
37 | * The console command description. |
||
38 | * |
||
39 | * @var string|null |
||
40 | */ |
||
41 | protected $description = 'Start the Laravel WebSocket Server'; |
||
42 | |||
43 | /** |
||
44 | * Get the loop instance. |
||
45 | * |
||
46 | * @var \React\EventLoop\LoopInterface |
||
47 | */ |
||
48 | protected $loop; |
||
49 | |||
50 | /** |
||
51 | * The Pusher server instance. |
||
52 | * |
||
53 | * @var \Ratchet\Server\IoServer |
||
54 | */ |
||
55 | public $server; |
||
56 | |||
57 | /** |
||
58 | * Track the last restart. |
||
59 | * |
||
60 | * @var int |
||
61 | */ |
||
62 | protected $lastRestart; |
||
63 | |||
64 | /** |
||
65 | * Initialize the command. |
||
66 | * |
||
67 | * @return void |
||
|
|||
68 | */ |
||
69 | public function __construct() |
||
75 | |||
76 | /** |
||
77 | * Run the command. |
||
78 | * |
||
79 | * @return void |
||
80 | */ |
||
81 | public function handle() |
||
93 | |||
94 | /** |
||
95 | * Configure the statistics logger class. |
||
96 | * |
||
97 | * @return $this |
||
98 | */ |
||
99 | protected function configureStatisticsLogger() |
||
118 | |||
119 | /** |
||
120 | * Configure the HTTP logger class. |
||
121 | * |
||
122 | * @return $this |
||
123 | */ |
||
124 | View Code Duplication | protected function configureHttpLogger() |
|
134 | |||
135 | /** |
||
136 | * Configure the logger for messages. |
||
137 | * |
||
138 | * @return $this |
||
139 | */ |
||
140 | View Code Duplication | protected function configureMessageLogger() |
|
150 | |||
151 | /** |
||
152 | * Configure the connection logger. |
||
153 | * |
||
154 | * @return $this |
||
155 | */ |
||
156 | View Code Duplication | protected function configureConnectionLogger() |
|
166 | |||
167 | /** |
||
168 | * Configure the Redis PubSub handler. |
||
169 | * |
||
170 | * @return $this |
||
171 | */ |
||
172 | public function configureRestartTimer() |
||
184 | |||
185 | /** |
||
186 | * Configure the replicators. |
||
187 | * |
||
188 | * @return void |
||
189 | */ |
||
190 | public function configurePubSub() |
||
210 | |||
211 | /** |
||
212 | * Register the routes. |
||
213 | * |
||
214 | * @return $this |
||
215 | */ |
||
216 | protected function registerRoutes() |
||
222 | |||
223 | /** |
||
224 | * Start the server. |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | protected function startWebSocketServer() |
||
245 | |||
246 | /** |
||
247 | * Build the server instance. |
||
248 | * |
||
249 | * @return void |
||
250 | */ |
||
251 | protected function buildServer() |
||
263 | |||
264 | /** |
||
265 | * Get the last time the server restarted. |
||
266 | * |
||
267 | * @return int |
||
268 | */ |
||
269 | protected function getLastRestart() |
||
273 | } |
||
274 |
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.