Complex classes like Command 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Command, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class Command |
||
| 13 | { |
||
| 14 | protected $pidFile; |
||
| 15 | |||
| 16 | protected $options = []; |
||
| 17 | |||
| 18 | protected $host = '127.0.0.1'; |
||
| 19 | |||
| 20 | protected $port = 8083; |
||
| 21 | |||
| 22 | protected $bootstrap = 'bootstrap/app.php'; |
||
| 23 | |||
| 24 | protected $serverOptions = []; |
||
| 25 | |||
| 26 | public function __construct() |
||
| 30 | |||
| 31 | public static function main($argv) |
||
| 37 | |||
| 38 | public function run($argv) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param array $argv |
||
| 56 | * |
||
| 57 | * @return bool |
||
| 58 | */ |
||
| 59 | public function handleAction($argv) |
||
| 73 | |||
| 74 | public function handleArguments() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Show usage. |
||
| 135 | */ |
||
| 136 | public function usage() |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Stop the server. |
||
| 175 | * |
||
| 176 | * @throws \Exception |
||
| 177 | * |
||
| 178 | * @return void |
||
| 179 | */ |
||
| 180 | public function stop() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Reload the server. |
||
| 197 | * |
||
| 198 | * @throws \Exception |
||
| 199 | * |
||
| 200 | * @return void |
||
| 201 | */ |
||
| 202 | public function reload() |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Restart the server. |
||
| 209 | * |
||
| 210 | * @return void |
||
| 211 | */ |
||
| 212 | public function restart() |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Get process identifier of this server. |
||
| 233 | * |
||
| 234 | * @throws \Exception |
||
| 235 | * |
||
| 236 | * @return bool|string |
||
| 237 | */ |
||
| 238 | protected function getPid() |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Set the error handling for the application. |
||
| 259 | * |
||
| 260 | * @return void |
||
| 261 | */ |
||
| 262 | protected function registerErrorHandling() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Handle an uncaught exception instance. |
||
| 283 | * |
||
| 284 | * @param \Exception $e |
||
| 285 | * |
||
| 286 | * @return void |
||
| 287 | */ |
||
| 288 | protected function handleUncaughtException($e) |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Handle the application shutdown routine. |
||
| 299 | * |
||
| 300 | * @return void |
||
| 301 | */ |
||
| 302 | protected function handleShutdown() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Determine if the error type is fatal. |
||
| 317 | * |
||
| 318 | * @param int $type |
||
| 319 | * |
||
| 320 | * @return bool |
||
| 321 | */ |
||
| 322 | protected function isFatalError($type) |
||
| 332 | } |
||
| 333 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: