Complex classes like HostConfig 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 HostConfig, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class HostConfig |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var string[] |
||
| 9 | */ |
||
| 10 | protected $binds; |
||
| 11 | /** |
||
| 12 | * @var string[] |
||
| 13 | */ |
||
| 14 | protected $links; |
||
| 15 | /** |
||
| 16 | * @var string[] |
||
| 17 | */ |
||
| 18 | protected $lxcConf; |
||
| 19 | /** |
||
| 20 | * @var int |
||
| 21 | */ |
||
| 22 | protected $memory; |
||
| 23 | /** |
||
| 24 | * @var int |
||
| 25 | */ |
||
| 26 | protected $memorySwap; |
||
| 27 | /** |
||
| 28 | * @var int |
||
| 29 | */ |
||
| 30 | protected $cpuShares; |
||
| 31 | /** |
||
| 32 | * @var int |
||
| 33 | */ |
||
| 34 | protected $cpuPeriod; |
||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | protected $cpusetCpus; |
||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | protected $cpusetMems; |
||
| 43 | /** |
||
| 44 | * @var int |
||
| 45 | */ |
||
| 46 | protected $blkioWeight; |
||
| 47 | /** |
||
| 48 | * @var int |
||
| 49 | */ |
||
| 50 | protected $memorySwappiness; |
||
| 51 | /** |
||
| 52 | * @var bool |
||
| 53 | */ |
||
| 54 | protected $oomKillDisable; |
||
| 55 | /** |
||
| 56 | * @var PortBinding[] |
||
| 57 | */ |
||
| 58 | protected $portBindings; |
||
| 59 | /** |
||
| 60 | * @var bool |
||
| 61 | */ |
||
| 62 | protected $publishAllPorts; |
||
| 63 | /** |
||
| 64 | * @var bool |
||
| 65 | */ |
||
| 66 | protected $privileged; |
||
| 67 | /** |
||
| 68 | * @var bool |
||
| 69 | */ |
||
| 70 | protected $readonlyRootfs; |
||
| 71 | /** |
||
| 72 | * @var string[] |
||
| 73 | */ |
||
| 74 | protected $dns; |
||
| 75 | /** |
||
| 76 | * @var string[] |
||
| 77 | */ |
||
| 78 | protected $dnsSearch; |
||
| 79 | /** |
||
| 80 | * @var string[] |
||
| 81 | */ |
||
| 82 | protected $extraHosts; |
||
| 83 | /** |
||
| 84 | * @var string[] |
||
| 85 | */ |
||
| 86 | protected $volumesFrom; |
||
| 87 | /** |
||
| 88 | * @var string[] |
||
| 89 | */ |
||
| 90 | protected $capAdd; |
||
| 91 | /** |
||
| 92 | * @var string[] |
||
| 93 | */ |
||
| 94 | protected $capDrop; |
||
| 95 | /** |
||
| 96 | * @var RestartPolicy |
||
| 97 | */ |
||
| 98 | protected $restartPolicy; |
||
| 99 | /** |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | protected $networkMode; |
||
| 103 | /** |
||
| 104 | * @var Device[] |
||
| 105 | */ |
||
| 106 | protected $devices; |
||
| 107 | /** |
||
| 108 | * @var Ulimit[] |
||
| 109 | */ |
||
| 110 | protected $ulimits; |
||
| 111 | /** |
||
| 112 | * @var string[] |
||
| 113 | */ |
||
| 114 | protected $securityOpt; |
||
| 115 | /** |
||
| 116 | * @var LogConfig |
||
| 117 | */ |
||
| 118 | protected $logConfig; |
||
| 119 | /** |
||
| 120 | * @var string |
||
| 121 | */ |
||
| 122 | protected $cgroupParent; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @return string[] |
||
| 126 | */ |
||
| 127 | public function getBinds() |
||
| 128 | { |
||
| 129 | return $this->binds; |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @param string[] $binds |
||
| 134 | * |
||
| 135 | * @return self |
||
| 136 | */ |
||
| 137 | public function setBinds(array $binds = null) |
||
| 138 | { |
||
| 139 | $this->binds = $binds; |
||
| 140 | |||
| 141 | return $this; |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @return string[] |
||
| 146 | */ |
||
| 147 | public function getLinks() |
||
| 148 | { |
||
| 149 | return $this->links; |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @param string[] $links |
||
| 154 | * |
||
| 155 | * @return self |
||
| 156 | */ |
||
| 157 | public function setLinks(array $links = null) |
||
| 158 | { |
||
| 159 | $this->links = $links; |
||
| 160 | |||
| 161 | return $this; |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @return string[] |
||
| 166 | */ |
||
| 167 | public function getLxcConf() |
||
| 168 | { |
||
| 169 | return $this->lxcConf; |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @param string[] $lxcConf |
||
| 174 | * |
||
| 175 | * @return self |
||
| 176 | */ |
||
| 177 | public function setLxcConf(\ArrayObject $lxcConf = null) |
||
| 178 | { |
||
| 179 | $this->lxcConf = $lxcConf; |
||
| 180 | |||
| 181 | return $this; |
||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @return int |
||
| 186 | */ |
||
| 187 | public function getMemory() |
||
| 188 | { |
||
| 189 | return $this->memory; |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @param int $memory |
||
| 194 | * |
||
| 195 | * @return self |
||
| 196 | */ |
||
| 197 | public function setMemory($memory = null) |
||
| 198 | { |
||
| 199 | $this->memory = $memory; |
||
| 200 | |||
| 201 | return $this; |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return int |
||
| 206 | */ |
||
| 207 | public function getMemorySwap() |
||
| 208 | { |
||
| 209 | return $this->memorySwap; |
||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param int $memorySwap |
||
| 214 | * |
||
| 215 | * @return self |
||
| 216 | */ |
||
| 217 | public function setMemorySwap($memorySwap = null) |
||
| 218 | { |
||
| 219 | $this->memorySwap = $memorySwap; |
||
| 220 | |||
| 221 | return $this; |
||
| 222 | } |
||
| 223 | |||
| 224 | /** |
||
| 225 | * @return int |
||
| 226 | */ |
||
| 227 | public function getCpuShares() |
||
| 228 | { |
||
| 229 | return $this->cpuShares; |
||
| 230 | } |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @param int $cpuShares |
||
| 234 | * |
||
| 235 | * @return self |
||
| 236 | */ |
||
| 237 | public function setCpuShares($cpuShares = null) |
||
| 238 | { |
||
| 239 | $this->cpuShares = $cpuShares; |
||
| 240 | |||
| 241 | return $this; |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @return int |
||
| 246 | */ |
||
| 247 | public function getCpuPeriod() |
||
| 248 | { |
||
| 249 | return $this->cpuPeriod; |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @param int $cpuPeriod |
||
| 254 | * |
||
| 255 | * @return self |
||
| 256 | */ |
||
| 257 | public function setCpuPeriod($cpuPeriod = null) |
||
| 258 | { |
||
| 259 | $this->cpuPeriod = $cpuPeriod; |
||
| 260 | |||
| 261 | return $this; |
||
| 262 | } |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @return string |
||
| 266 | */ |
||
| 267 | public function getCpusetCpus() |
||
| 268 | { |
||
| 269 | return $this->cpusetCpus; |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * @param string $cpusetCpus |
||
| 274 | * |
||
| 275 | * @return self |
||
| 276 | */ |
||
| 277 | public function setCpusetCpus($cpusetCpus = null) |
||
| 278 | { |
||
| 279 | $this->cpusetCpus = $cpusetCpus; |
||
| 280 | |||
| 281 | return $this; |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @return string |
||
| 286 | */ |
||
| 287 | public function getCpusetMems() |
||
| 288 | { |
||
| 289 | return $this->cpusetMems; |
||
| 290 | } |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @param string $cpusetMems |
||
| 294 | * |
||
| 295 | * @return self |
||
| 296 | */ |
||
| 297 | public function setCpusetMems($cpusetMems = null) |
||
| 298 | { |
||
| 299 | $this->cpusetMems = $cpusetMems; |
||
| 300 | |||
| 301 | return $this; |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @return int |
||
| 306 | */ |
||
| 307 | public function getBlkioWeight() |
||
| 308 | { |
||
| 309 | return $this->blkioWeight; |
||
| 310 | } |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @param int $blkioWeight |
||
| 314 | * |
||
| 315 | * @return self |
||
| 316 | */ |
||
| 317 | public function setBlkioWeight($blkioWeight = null) |
||
| 318 | { |
||
| 319 | $this->blkioWeight = $blkioWeight; |
||
| 320 | |||
| 321 | return $this; |
||
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @return int |
||
| 326 | */ |
||
| 327 | public function getMemorySwappiness() |
||
| 328 | { |
||
| 329 | return $this->memorySwappiness; |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @param int $memorySwappiness |
||
| 334 | * |
||
| 335 | * @return self |
||
| 336 | */ |
||
| 337 | public function setMemorySwappiness($memorySwappiness = null) |
||
| 338 | { |
||
| 339 | $this->memorySwappiness = $memorySwappiness; |
||
| 340 | |||
| 341 | return $this; |
||
| 342 | } |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @return bool |
||
| 346 | */ |
||
| 347 | public function getOomKillDisable() |
||
| 348 | { |
||
| 349 | return $this->oomKillDisable; |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @param bool $oomKillDisable |
||
| 354 | * |
||
| 355 | * @return self |
||
| 356 | */ |
||
| 357 | public function setOomKillDisable($oomKillDisable = null) |
||
| 358 | { |
||
| 359 | $this->oomKillDisable = $oomKillDisable; |
||
| 360 | |||
| 361 | return $this; |
||
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @return PortBinding[] |
||
| 366 | */ |
||
| 367 | public function getPortBindings() |
||
| 368 | { |
||
| 369 | return $this->portBindings; |
||
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @param PortBinding[] $portBindings |
||
| 374 | * |
||
| 375 | * @return self |
||
| 376 | */ |
||
| 377 | public function setPortBindings(\ArrayObject $portBindings = null) |
||
| 378 | { |
||
| 379 | $this->portBindings = $portBindings; |
||
| 380 | |||
| 381 | return $this; |
||
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * @return bool |
||
| 386 | */ |
||
| 387 | public function getPublishAllPorts() |
||
| 388 | { |
||
| 389 | return $this->publishAllPorts; |
||
| 390 | } |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @param bool $publishAllPorts |
||
| 394 | * |
||
| 395 | * @return self |
||
| 396 | */ |
||
| 397 | public function setPublishAllPorts($publishAllPorts = null) |
||
| 398 | { |
||
| 399 | $this->publishAllPorts = $publishAllPorts; |
||
| 400 | |||
| 401 | return $this; |
||
| 402 | } |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @return bool |
||
| 406 | */ |
||
| 407 | public function getPrivileged() |
||
| 408 | { |
||
| 409 | return $this->privileged; |
||
| 410 | } |
||
| 411 | |||
| 412 | /** |
||
| 413 | * @param bool $privileged |
||
| 414 | * |
||
| 415 | * @return self |
||
| 416 | */ |
||
| 417 | public function setPrivileged($privileged = null) |
||
| 418 | { |
||
| 419 | $this->privileged = $privileged; |
||
| 420 | |||
| 421 | return $this; |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @return bool |
||
| 426 | */ |
||
| 427 | public function getReadonlyRootfs() |
||
| 428 | { |
||
| 429 | return $this->readonlyRootfs; |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @param bool $readonlyRootfs |
||
| 434 | * |
||
| 435 | * @return self |
||
| 436 | */ |
||
| 437 | public function setReadonlyRootfs($readonlyRootfs = null) |
||
| 438 | { |
||
| 439 | $this->readonlyRootfs = $readonlyRootfs; |
||
| 440 | |||
| 441 | return $this; |
||
| 442 | } |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @return string[] |
||
| 446 | */ |
||
| 447 | public function getDns() |
||
| 448 | { |
||
| 449 | return $this->dns; |
||
| 450 | } |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @param string[] $dns |
||
| 454 | * |
||
| 455 | * @return self |
||
| 456 | */ |
||
| 457 | public function setDns(array $dns = null) |
||
| 458 | { |
||
| 459 | $this->dns = $dns; |
||
| 460 | |||
| 461 | return $this; |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @return string[] |
||
| 466 | */ |
||
| 467 | public function getDnsSearch() |
||
| 468 | { |
||
| 469 | return $this->dnsSearch; |
||
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @param string[] $dnsSearch |
||
| 474 | * |
||
| 475 | * @return self |
||
| 476 | */ |
||
| 477 | public function setDnsSearch(array $dnsSearch = null) |
||
| 478 | { |
||
| 479 | $this->dnsSearch = $dnsSearch; |
||
| 480 | |||
| 481 | return $this; |
||
| 482 | } |
||
| 483 | |||
| 484 | /** |
||
| 485 | * @return string[] |
||
| 486 | */ |
||
| 487 | public function getExtraHosts() |
||
| 488 | { |
||
| 489 | return $this->extraHosts; |
||
| 490 | } |
||
| 491 | |||
| 492 | /** |
||
| 493 | * @param string[] $extraHosts |
||
| 494 | * |
||
| 495 | * @return self |
||
| 496 | */ |
||
| 497 | public function setExtraHosts(array $extraHosts = null) |
||
| 498 | { |
||
| 499 | $this->extraHosts = $extraHosts; |
||
| 500 | |||
| 501 | return $this; |
||
| 502 | } |
||
| 503 | |||
| 504 | /** |
||
| 505 | * @return string[] |
||
| 506 | */ |
||
| 507 | public function getVolumesFrom() |
||
| 508 | { |
||
| 509 | return $this->volumesFrom; |
||
| 510 | } |
||
| 511 | |||
| 512 | /** |
||
| 513 | * @param string[] $volumesFrom |
||
| 514 | * |
||
| 515 | * @return self |
||
| 516 | */ |
||
| 517 | public function setVolumesFrom(array $volumesFrom = null) |
||
| 518 | { |
||
| 519 | $this->volumesFrom = $volumesFrom; |
||
| 520 | |||
| 521 | return $this; |
||
| 522 | } |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @return string[] |
||
| 526 | */ |
||
| 527 | public function getCapAdd() |
||
| 528 | { |
||
| 529 | return $this->capAdd; |
||
| 530 | } |
||
| 531 | |||
| 532 | /** |
||
| 533 | * @param string[] $capAdd |
||
| 534 | * |
||
| 535 | * @return self |
||
| 536 | */ |
||
| 537 | public function setCapAdd(array $capAdd = null) |
||
| 538 | { |
||
| 539 | $this->capAdd = $capAdd; |
||
| 540 | |||
| 541 | return $this; |
||
| 542 | } |
||
| 543 | |||
| 544 | /** |
||
| 545 | * @return string[] |
||
| 546 | */ |
||
| 547 | public function getCapDrop() |
||
| 548 | { |
||
| 549 | return $this->capDrop; |
||
| 550 | } |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @param string[] $capDrop |
||
| 554 | * |
||
| 555 | * @return self |
||
| 556 | */ |
||
| 557 | public function setCapDrop(array $capDrop = null) |
||
| 558 | { |
||
| 559 | $this->capDrop = $capDrop; |
||
| 560 | |||
| 561 | return $this; |
||
| 562 | } |
||
| 563 | |||
| 564 | /** |
||
| 565 | * @return RestartPolicy |
||
| 566 | */ |
||
| 567 | public function getRestartPolicy() |
||
| 568 | { |
||
| 569 | return $this->restartPolicy; |
||
| 570 | } |
||
| 571 | |||
| 572 | /** |
||
| 573 | * @param RestartPolicy $restartPolicy |
||
| 574 | * |
||
| 575 | * @return self |
||
| 576 | */ |
||
| 577 | public function setRestartPolicy(RestartPolicy $restartPolicy = null) |
||
| 578 | { |
||
| 579 | $this->restartPolicy = $restartPolicy; |
||
| 580 | |||
| 581 | return $this; |
||
| 582 | } |
||
| 583 | |||
| 584 | /** |
||
| 585 | * @return string |
||
| 586 | */ |
||
| 587 | public function getNetworkMode() |
||
| 588 | { |
||
| 589 | return $this->networkMode; |
||
| 590 | } |
||
| 591 | |||
| 592 | /** |
||
| 593 | * @param string $networkMode |
||
| 594 | * |
||
| 595 | * @return self |
||
| 596 | */ |
||
| 597 | public function setNetworkMode($networkMode = null) |
||
| 598 | { |
||
| 599 | $this->networkMode = $networkMode; |
||
| 600 | |||
| 601 | return $this; |
||
| 602 | } |
||
| 603 | |||
| 604 | /** |
||
| 605 | * @return Device[] |
||
| 606 | */ |
||
| 607 | public function getDevices() |
||
| 608 | { |
||
| 609 | return $this->devices; |
||
| 610 | } |
||
| 611 | |||
| 612 | /** |
||
| 613 | * @param Device[] $devices |
||
| 614 | * |
||
| 615 | * @return self |
||
| 616 | */ |
||
| 617 | public function setDevices(array $devices = null) |
||
| 618 | { |
||
| 619 | $this->devices = $devices; |
||
| 620 | |||
| 621 | return $this; |
||
| 622 | } |
||
| 623 | |||
| 624 | /** |
||
| 625 | * @return Ulimit[] |
||
| 626 | */ |
||
| 627 | public function getUlimits() |
||
| 628 | { |
||
| 629 | return $this->ulimits; |
||
| 630 | } |
||
| 631 | |||
| 632 | /** |
||
| 633 | * @param Ulimit[] $ulimits |
||
| 634 | * |
||
| 635 | * @return self |
||
| 636 | */ |
||
| 637 | public function setUlimits(array $ulimits = null) |
||
| 638 | { |
||
| 639 | $this->ulimits = $ulimits; |
||
| 640 | |||
| 641 | return $this; |
||
| 642 | } |
||
| 643 | |||
| 644 | /** |
||
| 645 | * @return string[] |
||
| 646 | */ |
||
| 647 | public function getSecurityOpt() |
||
| 648 | { |
||
| 649 | return $this->securityOpt; |
||
| 650 | } |
||
| 651 | |||
| 652 | /** |
||
| 653 | * @param string[] $securityOpt |
||
| 654 | * |
||
| 655 | * @return self |
||
| 656 | */ |
||
| 657 | public function setSecurityOpt(array $securityOpt = null) |
||
| 658 | { |
||
| 659 | $this->securityOpt = $securityOpt; |
||
| 660 | |||
| 661 | return $this; |
||
| 662 | } |
||
| 663 | |||
| 664 | /** |
||
| 665 | * @return LogConfig |
||
| 666 | */ |
||
| 667 | public function getLogConfig() |
||
| 668 | { |
||
| 669 | return $this->logConfig; |
||
| 670 | } |
||
| 671 | |||
| 672 | /** |
||
| 673 | * @param LogConfig $logConfig |
||
| 674 | * |
||
| 675 | * @return self |
||
| 676 | */ |
||
| 677 | public function setLogConfig(LogConfig $logConfig = null) |
||
| 678 | { |
||
| 679 | $this->logConfig = $logConfig; |
||
| 680 | |||
| 681 | return $this; |
||
| 682 | } |
||
| 683 | |||
| 684 | /** |
||
| 685 | * @return string |
||
| 686 | */ |
||
| 687 | public function getCgroupParent() |
||
| 688 | { |
||
| 689 | return $this->cgroupParent; |
||
| 690 | } |
||
| 691 | |||
| 692 | /** |
||
| 693 | * @param string $cgroupParent |
||
| 694 | * |
||
| 695 | * @return self |
||
| 696 | */ |
||
| 697 | public function setCgroupParent($cgroupParent = null) |
||
| 698 | { |
||
| 699 | $this->cgroupParent = $cgroupParent; |
||
| 700 | |||
| 701 | return $this; |
||
| 702 | } |
||
| 703 | } |
||
| 704 |