Complex classes like ContainerConfig 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 ContainerConfig, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class ContainerConfig |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var string |
||
| 9 | */ |
||
| 10 | protected $id; |
||
| 11 | /** |
||
| 12 | * @var string[] |
||
| 13 | */ |
||
| 14 | protected $names; |
||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | protected $image; |
||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $command; |
||
| 23 | /** |
||
| 24 | * @var int |
||
| 25 | */ |
||
| 26 | protected $created; |
||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $status; |
||
| 31 | /** |
||
| 32 | * @var Port[] |
||
| 33 | */ |
||
| 34 | protected $ports; |
||
| 35 | /** |
||
| 36 | * @var string[] |
||
| 37 | */ |
||
| 38 | protected $labels; |
||
| 39 | /** |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | protected $sizeRw; |
||
| 43 | /** |
||
| 44 | * @var int |
||
| 45 | */ |
||
| 46 | protected $sizeRootFs; |
||
| 47 | /** |
||
| 48 | * @var int |
||
| 49 | */ |
||
| 50 | protected $hostname; |
||
| 51 | /** |
||
| 52 | * @var int |
||
| 53 | */ |
||
| 54 | protected $domainname; |
||
| 55 | /** |
||
| 56 | * @var int |
||
| 57 | */ |
||
| 58 | protected $user; |
||
| 59 | /** |
||
| 60 | * @var bool |
||
| 61 | */ |
||
| 62 | protected $attachStdin; |
||
| 63 | /** |
||
| 64 | * @var bool |
||
| 65 | */ |
||
| 66 | protected $attachStdout; |
||
| 67 | /** |
||
| 68 | * @var bool |
||
| 69 | */ |
||
| 70 | protected $attachStderr; |
||
| 71 | /** |
||
| 72 | * @var bool |
||
| 73 | */ |
||
| 74 | protected $tty; |
||
| 75 | /** |
||
| 76 | * @var bool |
||
| 77 | */ |
||
| 78 | protected $openStdin; |
||
| 79 | /** |
||
| 80 | * @var bool |
||
| 81 | */ |
||
| 82 | protected $stdinOnce; |
||
| 83 | /** |
||
| 84 | * @var string[] |
||
| 85 | */ |
||
| 86 | protected $env; |
||
| 87 | /** |
||
| 88 | * @var string[]|string |
||
| 89 | */ |
||
| 90 | protected $cmd; |
||
| 91 | /** |
||
| 92 | * @var string[]|string |
||
| 93 | */ |
||
| 94 | protected $entrypoint; |
||
| 95 | /** |
||
| 96 | * @var Mount[] |
||
| 97 | */ |
||
| 98 | protected $mounts; |
||
| 99 | /** |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | protected $workingDir; |
||
| 103 | /** |
||
| 104 | * @var bool |
||
| 105 | */ |
||
| 106 | protected $networkDisabled; |
||
| 107 | /** |
||
| 108 | * @var string |
||
| 109 | */ |
||
| 110 | protected $macAddress; |
||
| 111 | /** |
||
| 112 | * @var mixed[] |
||
| 113 | */ |
||
| 114 | protected $exposedPorts; |
||
| 115 | /** |
||
| 116 | * @var HostConfig |
||
| 117 | */ |
||
| 118 | protected $hostConfig; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @return string |
||
| 122 | */ |
||
| 123 | public function getId() |
||
| 124 | { |
||
| 125 | return $this->id; |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param string $id |
||
| 130 | * |
||
| 131 | * @return self |
||
| 132 | */ |
||
| 133 | public function setId($id = null) |
||
| 134 | { |
||
| 135 | $this->id = $id; |
||
| 136 | |||
| 137 | return $this; |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @return string[] |
||
| 142 | */ |
||
| 143 | public function getNames() |
||
| 144 | { |
||
| 145 | return $this->names; |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param string[] $names |
||
| 150 | * |
||
| 151 | * @return self |
||
| 152 | */ |
||
| 153 | public function setNames(array $names = null) |
||
| 154 | { |
||
| 155 | $this->names = $names; |
||
| 156 | |||
| 157 | return $this; |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @return string |
||
| 162 | */ |
||
| 163 | public function getImage() |
||
| 164 | { |
||
| 165 | return $this->image; |
||
| 166 | } |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @param string $image |
||
| 170 | * |
||
| 171 | * @return self |
||
| 172 | */ |
||
| 173 | public function setImage($image = null) |
||
| 174 | { |
||
| 175 | $this->image = $image; |
||
| 176 | |||
| 177 | return $this; |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @return string |
||
| 182 | */ |
||
| 183 | public function getCommand() |
||
| 184 | { |
||
| 185 | return $this->command; |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param string $command |
||
| 190 | * |
||
| 191 | * @return self |
||
| 192 | */ |
||
| 193 | public function setCommand($command = null) |
||
| 194 | { |
||
| 195 | $this->command = $command; |
||
| 196 | |||
| 197 | return $this; |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @return int |
||
| 202 | */ |
||
| 203 | public function getCreated() |
||
| 204 | { |
||
| 205 | return $this->created; |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @param int $created |
||
| 210 | * |
||
| 211 | * @return self |
||
| 212 | */ |
||
| 213 | public function setCreated($created = null) |
||
| 214 | { |
||
| 215 | $this->created = $created; |
||
| 216 | |||
| 217 | return $this; |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | public function getStatus() |
||
| 224 | { |
||
| 225 | return $this->status; |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @param string $status |
||
| 230 | * |
||
| 231 | * @return self |
||
| 232 | */ |
||
| 233 | public function setStatus($status = null) |
||
| 234 | { |
||
| 235 | $this->status = $status; |
||
| 236 | |||
| 237 | return $this; |
||
| 238 | } |
||
| 239 | |||
| 240 | /** |
||
| 241 | * @return Port[] |
||
| 242 | */ |
||
| 243 | public function getPorts() |
||
| 244 | { |
||
| 245 | return $this->ports; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @param Port[] $ports |
||
| 250 | * |
||
| 251 | * @return self |
||
| 252 | */ |
||
| 253 | public function setPorts(array $ports = null) |
||
| 254 | { |
||
| 255 | $this->ports = $ports; |
||
| 256 | |||
| 257 | return $this; |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @return string[] |
||
| 262 | */ |
||
| 263 | public function getLabels() |
||
| 264 | { |
||
| 265 | return $this->labels; |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @param string[] $labels |
||
| 270 | * |
||
| 271 | * @return self |
||
| 272 | */ |
||
| 273 | public function setLabels(\ArrayObject $labels = null) |
||
| 274 | { |
||
| 275 | $this->labels = $labels; |
||
| 276 | |||
| 277 | return $this; |
||
| 278 | } |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @return int |
||
| 282 | */ |
||
| 283 | public function getSizeRw() |
||
| 284 | { |
||
| 285 | return $this->sizeRw; |
||
| 286 | } |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param int $sizeRw |
||
| 290 | * |
||
| 291 | * @return self |
||
| 292 | */ |
||
| 293 | public function setSizeRw($sizeRw = null) |
||
| 294 | { |
||
| 295 | $this->sizeRw = $sizeRw; |
||
| 296 | |||
| 297 | return $this; |
||
| 298 | } |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @return int |
||
| 302 | */ |
||
| 303 | public function getSizeRootFs() |
||
| 304 | { |
||
| 305 | return $this->sizeRootFs; |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @param int $sizeRootFs |
||
| 310 | * |
||
| 311 | * @return self |
||
| 312 | */ |
||
| 313 | public function setSizeRootFs($sizeRootFs = null) |
||
| 314 | { |
||
| 315 | $this->sizeRootFs = $sizeRootFs; |
||
| 316 | |||
| 317 | return $this; |
||
| 318 | } |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @return int |
||
| 322 | */ |
||
| 323 | public function getHostname() |
||
| 324 | { |
||
| 325 | return $this->hostname; |
||
| 326 | } |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @param int $hostname |
||
| 330 | * |
||
| 331 | * @return self |
||
| 332 | */ |
||
| 333 | public function setHostname($hostname = null) |
||
| 334 | { |
||
| 335 | $this->hostname = $hostname; |
||
| 336 | |||
| 337 | return $this; |
||
| 338 | } |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @return int |
||
| 342 | */ |
||
| 343 | public function getDomainname() |
||
| 344 | { |
||
| 345 | return $this->domainname; |
||
| 346 | } |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @param int $domainname |
||
| 350 | * |
||
| 351 | * @return self |
||
| 352 | */ |
||
| 353 | public function setDomainname($domainname = null) |
||
| 354 | { |
||
| 355 | $this->domainname = $domainname; |
||
| 356 | |||
| 357 | return $this; |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @return int |
||
| 362 | */ |
||
| 363 | public function getUser() |
||
| 364 | { |
||
| 365 | return $this->user; |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @param int $user |
||
| 370 | * |
||
| 371 | * @return self |
||
| 372 | */ |
||
| 373 | public function setUser($user = null) |
||
| 374 | { |
||
| 375 | $this->user = $user; |
||
| 376 | |||
| 377 | return $this; |
||
| 378 | } |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @return bool |
||
| 382 | */ |
||
| 383 | public function getAttachStdin() |
||
| 384 | { |
||
| 385 | return $this->attachStdin; |
||
| 386 | } |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @param bool $attachStdin |
||
| 390 | * |
||
| 391 | * @return self |
||
| 392 | */ |
||
| 393 | public function setAttachStdin($attachStdin = null) |
||
| 394 | { |
||
| 395 | $this->attachStdin = $attachStdin; |
||
| 396 | |||
| 397 | return $this; |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @return bool |
||
| 402 | */ |
||
| 403 | public function getAttachStdout() |
||
| 404 | { |
||
| 405 | return $this->attachStdout; |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @param bool $attachStdout |
||
| 410 | * |
||
| 411 | * @return self |
||
| 412 | */ |
||
| 413 | public function setAttachStdout($attachStdout = null) |
||
| 414 | { |
||
| 415 | $this->attachStdout = $attachStdout; |
||
| 416 | |||
| 417 | return $this; |
||
| 418 | } |
||
| 419 | |||
| 420 | /** |
||
| 421 | * @return bool |
||
| 422 | */ |
||
| 423 | public function getAttachStderr() |
||
| 424 | { |
||
| 425 | return $this->attachStderr; |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @param bool $attachStderr |
||
| 430 | * |
||
| 431 | * @return self |
||
| 432 | */ |
||
| 433 | public function setAttachStderr($attachStderr = null) |
||
| 434 | { |
||
| 435 | $this->attachStderr = $attachStderr; |
||
| 436 | |||
| 437 | return $this; |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @return bool |
||
| 442 | */ |
||
| 443 | public function getTty() |
||
| 444 | { |
||
| 445 | return $this->tty; |
||
| 446 | } |
||
| 447 | |||
| 448 | /** |
||
| 449 | * @param bool $tty |
||
| 450 | * |
||
| 451 | * @return self |
||
| 452 | */ |
||
| 453 | public function setTty($tty = null) |
||
| 454 | { |
||
| 455 | $this->tty = $tty; |
||
| 456 | |||
| 457 | return $this; |
||
| 458 | } |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @return bool |
||
| 462 | */ |
||
| 463 | public function getOpenStdin() |
||
| 464 | { |
||
| 465 | return $this->openStdin; |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * @param bool $openStdin |
||
| 470 | * |
||
| 471 | * @return self |
||
| 472 | */ |
||
| 473 | public function setOpenStdin($openStdin = null) |
||
| 474 | { |
||
| 475 | $this->openStdin = $openStdin; |
||
| 476 | |||
| 477 | return $this; |
||
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @return bool |
||
| 482 | */ |
||
| 483 | public function getStdinOnce() |
||
| 484 | { |
||
| 485 | return $this->stdinOnce; |
||
| 486 | } |
||
| 487 | |||
| 488 | /** |
||
| 489 | * @param bool $stdinOnce |
||
| 490 | * |
||
| 491 | * @return self |
||
| 492 | */ |
||
| 493 | public function setStdinOnce($stdinOnce = null) |
||
| 494 | { |
||
| 495 | $this->stdinOnce = $stdinOnce; |
||
| 496 | |||
| 497 | return $this; |
||
| 498 | } |
||
| 499 | |||
| 500 | /** |
||
| 501 | * @return string[] |
||
| 502 | */ |
||
| 503 | public function getEnv() |
||
| 504 | { |
||
| 505 | return $this->env; |
||
| 506 | } |
||
| 507 | |||
| 508 | /** |
||
| 509 | * @param string[] $env |
||
| 510 | * |
||
| 511 | * @return self |
||
| 512 | */ |
||
| 513 | public function setEnv(array $env = null) |
||
| 514 | { |
||
| 515 | $this->env = $env; |
||
| 516 | |||
| 517 | return $this; |
||
| 518 | } |
||
| 519 | |||
| 520 | /** |
||
| 521 | * @return string[]|string |
||
| 522 | */ |
||
| 523 | public function getCmd() |
||
| 524 | { |
||
| 525 | return $this->cmd; |
||
| 526 | } |
||
| 527 | |||
| 528 | /** |
||
| 529 | * @param string[]|string $cmd |
||
| 530 | * |
||
| 531 | * @return self |
||
| 532 | */ |
||
| 533 | public function setCmd($cmd = null) |
||
| 534 | { |
||
| 535 | $this->cmd = $cmd; |
||
| 536 | |||
| 537 | return $this; |
||
| 538 | } |
||
| 539 | |||
| 540 | /** |
||
| 541 | * @return string[]|string |
||
| 542 | */ |
||
| 543 | public function getEntrypoint() |
||
| 544 | { |
||
| 545 | return $this->entrypoint; |
||
| 546 | } |
||
| 547 | |||
| 548 | /** |
||
| 549 | * @param string[]|string $entrypoint |
||
| 550 | * |
||
| 551 | * @return self |
||
| 552 | */ |
||
| 553 | public function setEntrypoint($entrypoint = null) |
||
| 554 | { |
||
| 555 | $this->entrypoint = $entrypoint; |
||
| 556 | |||
| 557 | return $this; |
||
| 558 | } |
||
| 559 | |||
| 560 | /** |
||
| 561 | * @return Mount[] |
||
| 562 | */ |
||
| 563 | public function getMounts() |
||
| 564 | { |
||
| 565 | return $this->mounts; |
||
| 566 | } |
||
| 567 | |||
| 568 | /** |
||
| 569 | * @param Mount[] $mounts |
||
| 570 | * |
||
| 571 | * @return self |
||
| 572 | */ |
||
| 573 | public function setMounts(array $mounts = null) |
||
| 574 | { |
||
| 575 | $this->mounts = $mounts; |
||
| 576 | |||
| 577 | return $this; |
||
| 578 | } |
||
| 579 | |||
| 580 | /** |
||
| 581 | * @return string |
||
| 582 | */ |
||
| 583 | public function getWorkingDir() |
||
| 584 | { |
||
| 585 | return $this->workingDir; |
||
| 586 | } |
||
| 587 | |||
| 588 | /** |
||
| 589 | * @param string $workingDir |
||
| 590 | * |
||
| 591 | * @return self |
||
| 592 | */ |
||
| 593 | public function setWorkingDir($workingDir = null) |
||
| 594 | { |
||
| 595 | $this->workingDir = $workingDir; |
||
| 596 | |||
| 597 | return $this; |
||
| 598 | } |
||
| 599 | |||
| 600 | /** |
||
| 601 | * @return bool |
||
| 602 | */ |
||
| 603 | public function getNetworkDisabled() |
||
| 604 | { |
||
| 605 | return $this->networkDisabled; |
||
| 606 | } |
||
| 607 | |||
| 608 | /** |
||
| 609 | * @param bool $networkDisabled |
||
| 610 | * |
||
| 611 | * @return self |
||
| 612 | */ |
||
| 613 | public function setNetworkDisabled($networkDisabled = null) |
||
| 614 | { |
||
| 615 | $this->networkDisabled = $networkDisabled; |
||
| 616 | |||
| 617 | return $this; |
||
| 618 | } |
||
| 619 | |||
| 620 | /** |
||
| 621 | * @return string |
||
| 622 | */ |
||
| 623 | public function getMacAddress() |
||
| 624 | { |
||
| 625 | return $this->macAddress; |
||
| 626 | } |
||
| 627 | |||
| 628 | /** |
||
| 629 | * @param string $macAddress |
||
| 630 | * |
||
| 631 | * @return self |
||
| 632 | */ |
||
| 633 | public function setMacAddress($macAddress = null) |
||
| 634 | { |
||
| 635 | $this->macAddress = $macAddress; |
||
| 636 | |||
| 637 | return $this; |
||
| 638 | } |
||
| 639 | |||
| 640 | /** |
||
| 641 | * @return mixed[] |
||
| 642 | */ |
||
| 643 | public function getExposedPorts() |
||
| 644 | { |
||
| 645 | return $this->exposedPorts; |
||
| 646 | } |
||
| 647 | |||
| 648 | /** |
||
| 649 | * @param mixed[] $exposedPorts |
||
| 650 | * |
||
| 651 | * @return self |
||
| 652 | */ |
||
| 653 | public function setExposedPorts(\ArrayObject $exposedPorts = null) |
||
| 654 | { |
||
| 655 | $this->exposedPorts = $exposedPorts; |
||
| 656 | |||
| 657 | return $this; |
||
| 658 | } |
||
| 659 | |||
| 660 | /** |
||
| 661 | * @return HostConfig |
||
| 662 | */ |
||
| 663 | public function getHostConfig() |
||
| 664 | { |
||
| 665 | return $this->hostConfig; |
||
| 666 | } |
||
| 667 | |||
| 668 | /** |
||
| 669 | * @param HostConfig $hostConfig |
||
| 670 | * |
||
| 671 | * @return self |
||
| 672 | */ |
||
| 673 | public function setHostConfig(HostConfig $hostConfig = null) |
||
| 674 | { |
||
| 675 | $this->hostConfig = $hostConfig; |
||
| 676 | |||
| 677 | return $this; |
||
| 678 | } |
||
| 679 | } |
||
| 680 |