Total Complexity | 43 |
Total Lines | 206 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like LaravelSCommand often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use LaravelSCommand, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class LaravelSCommand extends Command |
||
8 | { |
||
9 | protected $signature = 'laravels {action? : publish|config|info} |
||
10 | {--d|daemonize : Whether run as a daemon for "start & restart"} |
||
11 | {--i|ignore : Whether ignore checking process pid for "start & restart"}'; |
||
12 | |||
13 | protected $description = 'LaravelS console tool'; |
||
14 | |||
15 | public function fire() |
||
16 | { |
||
17 | $this->handle(); |
||
18 | } |
||
19 | |||
20 | public function handle() |
||
21 | { |
||
22 | $action = (string)$this->argument('action'); |
||
23 | switch ($action) { |
||
24 | case 'publish': |
||
25 | $this->publish(); |
||
26 | break; |
||
27 | case 'config': |
||
28 | $this->prepareConfig(); |
||
29 | break; |
||
30 | case 'info': |
||
31 | $this->showInfo(); |
||
32 | break; |
||
33 | default: |
||
34 | $this->info(sprintf('Usage: [%s] ./artisan laravels publish|config|info', PHP_BINARY)); |
||
35 | break; |
||
36 | } |
||
37 | } |
||
38 | |||
39 | protected function isLumen() |
||
42 | } |
||
43 | |||
44 | protected function loadConfig() |
||
45 | { |
||
46 | // Load configuration laravel.php manually for Lumen |
||
47 | $basePath = config('laravels.laravel_base_path') ?: base_path(); |
||
48 | if ($this->isLumen() && file_exists($basePath . '/config/laravels.php')) { |
||
49 | $this->getLaravel()->configure('laravels'); |
||
|
|||
50 | } |
||
51 | } |
||
52 | |||
53 | protected function showInfo() |
||
92 | ], |
||
93 | ]); |
||
94 | } |
||
95 | |||
96 | protected function prepareConfig() |
||
122 | } |
||
123 | |||
124 | protected function preSet(array &$svrConf) |
||
125 | { |
||
126 | if (!isset($svrConf['enable_gzip'])) { |
||
127 | $svrConf['enable_gzip'] = false; |
||
128 | } |
||
129 | if (empty($svrConf['laravel_base_path'])) { |
||
130 | $svrConf['laravel_base_path'] = base_path(); |
||
131 | } |
||
132 | if (empty($svrConf['process_prefix'])) { |
||
133 | $svrConf['process_prefix'] = $svrConf['laravel_base_path']; |
||
134 | } |
||
135 | if ($this->option('ignore')) { |
||
136 | $svrConf['ignore_check_pid'] = true; |
||
137 | } elseif (!isset($svrConf['ignore_check_pid'])) { |
||
138 | $svrConf['ignore_check_pid'] = false; |
||
139 | } |
||
140 | if (empty($svrConf['swoole']['document_root'])) { |
||
141 | $svrConf['swoole']['document_root'] = $svrConf['laravel_base_path'] . '/public'; |
||
142 | } |
||
143 | if ($this->option('daemonize')) { |
||
144 | $svrConf['swoole']['daemonize'] = true; |
||
145 | } elseif (!isset($svrConf['swoole']['daemonize'])) { |
||
146 | $svrConf['swoole']['daemonize'] = false; |
||
147 | } |
||
148 | if (empty($svrConf['swoole']['pid_file'])) { |
||
149 | $svrConf['swoole']['pid_file'] = storage_path('laravels.pid'); |
||
150 | } |
||
151 | return 0; |
||
152 | } |
||
153 | |||
154 | protected function preCheck(array $svrConf) |
||
155 | { |
||
156 | if (!empty($svrConf['enable_gzip']) && version_compare(swoole_version(), '4.1.0', '>=')) { |
||
157 | $this->error('enable_gzip is DEPRECATED since Swoole 4.1.0, set http_compression of Swoole instead, http_compression is disabled by default.'); |
||
158 | $this->info('If there is a proxy server like Nginx, suggest that enable gzip in Nginx and disable gzip in Swoole, to avoid the repeated gzip compression for response.'); |
||
159 | return 1; |
||
160 | } |
||
161 | if (!empty($svrConf['events'])) { |
||
162 | if (empty($svrConf['swoole']['task_worker_num']) || $svrConf['swoole']['task_worker_num'] <= 0) { |
||
163 | $this->error('Asynchronous event listening needs to set task_worker_num > 0'); |
||
164 | return 1; |
||
165 | } |
||
166 | } |
||
167 | return 0; |
||
168 | } |
||
169 | |||
170 | |||
171 | public function publish() |
||
213 | } |
||
214 | } |
||
215 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.