Complex classes like Droplet 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 Droplet, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class Droplet extends AbstractApi |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @param int $per_page |
||
| 29 | * @param int $page |
||
| 30 | * @param string|null $tag |
||
| 31 | * |
||
| 32 | * @return DropletEntity[] |
||
| 33 | */ |
||
| 34 | public function getAll($per_page = 200, $page = 1, $tag = null) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return $total |
||
|
|
|||
| 53 | */ |
||
| 54 | public function getTotal() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param int $id |
||
| 65 | * |
||
| 66 | * @return DropletEntity[] |
||
| 67 | */ |
||
| 68 | public function getNeighborsById($id) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return DropletEntity[] |
||
| 81 | */ |
||
| 82 | public function getAllNeighbors() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @return UpgradeEntity[] |
||
| 95 | */ |
||
| 96 | public function getUpgrades() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param int $id |
||
| 109 | * |
||
| 110 | * @throws HttpException |
||
| 111 | * |
||
| 112 | * @return DropletEntity |
||
| 113 | */ |
||
| 114 | public function getById($id) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @param array|string $names |
||
| 125 | * @param string $region |
||
| 126 | * @param string $size |
||
| 127 | * @param string|int $image |
||
| 128 | * @param bool $backups |
||
| 129 | * @param bool $ipv6 |
||
| 130 | * @param bool $privateNetworking |
||
| 131 | * @param int[] $sshKeys |
||
| 132 | * @param string $userData |
||
| 133 | * @param bool $monitoring |
||
| 134 | * @param array $volumes |
||
| 135 | * @param array $tags |
||
| 136 | * @param bool $wait |
||
| 137 | * @param int $waitTimeout |
||
| 138 | * |
||
| 139 | * @throws HttpException |
||
| 140 | * |
||
| 141 | * @return DropletEntity|null |
||
| 142 | */ |
||
| 143 | public function create($names, $region, $size, $image, $backups = false, $ipv6 = false, $privateNetworking = false, array $sshKeys = [], $userData = '', $monitoring = true, array $volumes = [], array $tags = [], $wait = false, $waitTimeout = 300) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @param int $id |
||
| 198 | * |
||
| 199 | * @throws HttpException |
||
| 200 | */ |
||
| 201 | public function delete($id) |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @param int $id |
||
| 208 | * |
||
| 209 | * @throws HttpException |
||
| 210 | * |
||
| 211 | * @return KernelEntity[] |
||
| 212 | */ |
||
| 213 | public function getAvailableKernels($id) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @param int $id |
||
| 228 | * |
||
| 229 | * @return ImageEntity[] |
||
| 230 | */ |
||
| 231 | public function getSnapshots($id) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @param int $id |
||
| 248 | * |
||
| 249 | * @return ImageEntity[] |
||
| 250 | */ |
||
| 251 | public function getBackups($id) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @param int $id |
||
| 266 | * |
||
| 267 | * @return ActionEntity[] |
||
| 268 | */ |
||
| 269 | public function getActions($id) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @param int $id |
||
| 284 | * @param int $actionId |
||
| 285 | * |
||
| 286 | * @return ActionEntity |
||
| 287 | */ |
||
| 288 | public function getActionById($id, $actionId) |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @param int $id |
||
| 299 | * |
||
| 300 | * @throws HttpException |
||
| 301 | * |
||
| 302 | * @return ActionEntity |
||
| 303 | */ |
||
| 304 | public function reboot($id) |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @param int $id |
||
| 311 | * |
||
| 312 | * @throws HttpException |
||
| 313 | * |
||
| 314 | * @return ActionEntity |
||
| 315 | */ |
||
| 316 | public function powerCycle($id) |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @param int $id |
||
| 323 | * |
||
| 324 | * @throws HttpException |
||
| 325 | * |
||
| 326 | * @return ActionEntity |
||
| 327 | */ |
||
| 328 | public function shutdown($id) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @param int $id |
||
| 335 | * |
||
| 336 | * @throws HttpException |
||
| 337 | * |
||
| 338 | * @return ActionEntity |
||
| 339 | */ |
||
| 340 | public function powerOff($id) |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @param int $id |
||
| 347 | * |
||
| 348 | * @throws HttpException |
||
| 349 | * |
||
| 350 | * @return ActionEntity |
||
| 351 | */ |
||
| 352 | public function powerOn($id) |
||
| 356 | |||
| 357 | /** |
||
| 358 | * @param int $id |
||
| 359 | * |
||
| 360 | * @throws HttpException |
||
| 361 | * |
||
| 362 | * @return ActionEntity |
||
| 363 | */ |
||
| 364 | public function passwordReset($id) |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @param int $id |
||
| 371 | * @param string $size |
||
| 372 | * @param bool $disk |
||
| 373 | * |
||
| 374 | * @throws HttpException |
||
| 375 | * |
||
| 376 | * @return ActionEntity |
||
| 377 | */ |
||
| 378 | public function resize($id, $size, $disk = true) |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @param int $id |
||
| 385 | * @param int $image |
||
| 386 | * |
||
| 387 | * @throws HttpException |
||
| 388 | * |
||
| 389 | * @return ActionEntity |
||
| 390 | */ |
||
| 391 | public function restore($id, $image) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @param int $id |
||
| 398 | * @param int|string $image |
||
| 399 | * |
||
| 400 | * @throws HttpException |
||
| 401 | * |
||
| 402 | * @return ActionEntity |
||
| 403 | */ |
||
| 404 | public function rebuild($id, $image) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @param int $id |
||
| 411 | * @param string $name |
||
| 412 | * |
||
| 413 | * @throws HttpException |
||
| 414 | * |
||
| 415 | * @return ActionEntity |
||
| 416 | */ |
||
| 417 | public function rename($id, $name) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @param int $id |
||
| 424 | * @param int $kernel |
||
| 425 | * |
||
| 426 | * @throws HttpException |
||
| 427 | * |
||
| 428 | * @return ActionEntity |
||
| 429 | */ |
||
| 430 | public function changeKernel($id, $kernel) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @param int $id |
||
| 437 | * |
||
| 438 | * @throws HttpException |
||
| 439 | * |
||
| 440 | * @return ActionEntity |
||
| 441 | */ |
||
| 442 | public function enableIpv6($id) |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @param int $id |
||
| 449 | * |
||
| 450 | * @throws HttpException |
||
| 451 | * |
||
| 452 | * @return ActionEntity |
||
| 453 | */ |
||
| 454 | public function enableBackups($id) |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @param int $id |
||
| 461 | * |
||
| 462 | * @throws HttpException |
||
| 463 | * |
||
| 464 | * @return ActionEntity |
||
| 465 | */ |
||
| 466 | public function disableBackups($id) |
||
| 470 | |||
| 471 | /** |
||
| 472 | * @param int $id |
||
| 473 | * |
||
| 474 | * @throws HttpException |
||
| 475 | * |
||
| 476 | * @return ActionEntity |
||
| 477 | */ |
||
| 478 | public function enablePrivateNetworking($id) |
||
| 482 | |||
| 483 | /** |
||
| 484 | * @param int $id |
||
| 485 | * @param string $name |
||
| 486 | * |
||
| 487 | * @throws HttpException |
||
| 488 | * |
||
| 489 | * @return ActionEntity |
||
| 490 | */ |
||
| 491 | public function snapshot($id, $name) |
||
| 495 | |||
| 496 | /** |
||
| 497 | * @param int $id |
||
| 498 | * @param array $options |
||
| 499 | * |
||
| 500 | * @throws HttpException |
||
| 501 | * |
||
| 502 | * @return ActionEntity |
||
| 503 | */ |
||
| 504 | private function executeAction($id, array $options) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * @param DropletEntity $droplet |
||
| 515 | * @param int $waitTimeout |
||
| 516 | * |
||
| 517 | * @throws HttpException |
||
| 518 | * |
||
| 519 | * @return DropletEntity|null |
||
| 520 | */ |
||
| 521 | public function waitForActive($droplet, $waitTimeout) |
||
| 535 | } |
||
| 536 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.