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 | {--test : Prepare the server, but do not start it.} |
||
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() |
||
84 | |||
85 | /** |
||
86 | * Configure the loggers used for the console. |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | protected function configureLoggers() |
||
96 | |||
97 | /** |
||
98 | * Register the managers that are not resolved |
||
99 | * in the package service provider. |
||
100 | * |
||
101 | * @return void |
||
102 | */ |
||
103 | protected function configureManagers() |
||
113 | |||
114 | /** |
||
115 | * Register the Statistics Collectors that |
||
116 | * are not resolved in the package service provider. |
||
117 | * |
||
118 | * @return void |
||
119 | */ |
||
120 | protected function configureStatistics() |
||
132 | |||
133 | /** |
||
134 | * Configure the restart timer. |
||
135 | * |
||
136 | * @return void |
||
137 | */ |
||
138 | public function configureRestartTimer() |
||
148 | |||
149 | /** |
||
150 | * Register the routes for the server. |
||
151 | * |
||
152 | * @return void |
||
153 | */ |
||
154 | protected function configureRoutes() |
||
158 | |||
159 | /** |
||
160 | * Configure the HTTP logger class. |
||
161 | * |
||
162 | * @return void |
||
163 | */ |
||
164 | View Code Duplication | protected function configureHttpLogger() |
|
172 | |||
173 | /** |
||
174 | * Configure the logger for messages. |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | View Code Duplication | protected function configureMessageLogger() |
|
186 | |||
187 | /** |
||
188 | * Configure the connection logger. |
||
189 | * |
||
190 | * @return void |
||
191 | */ |
||
192 | protected function configureConnectionLogger() |
||
200 | |||
201 | /** |
||
202 | * Start the server. |
||
203 | * |
||
204 | * @return void |
||
205 | */ |
||
206 | protected function startServer() |
||
222 | |||
223 | /** |
||
224 | * Build the server instance. |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | protected function buildServer() |
||
240 | |||
241 | /** |
||
242 | * Get the last time the server restarted. |
||
243 | * |
||
244 | * @return int |
||
245 | */ |
||
246 | protected function getLastRestart() |
||
252 | } |
||
253 |
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.