Complex classes like Card 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 Card, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class Card { |
||
| 24 | |||
| 25 | use CardTrait; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Article number. |
||
| 29 | * |
||
| 30 | * @var int|null |
||
| 31 | */ |
||
| 32 | private $articleNumber; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Currency residual value. |
||
| 36 | * |
||
| 37 | * @var string|null |
||
| 38 | */ |
||
| 39 | private $currencyResidualValue; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Display text. |
||
| 43 | * |
||
| 44 | * @var bool|null |
||
| 45 | */ |
||
| 46 | private $displayText; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Display text 1. |
||
| 50 | * |
||
| 51 | * @var string|null |
||
| 52 | */ |
||
| 53 | private $displayText1; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Display text 2. |
||
| 57 | * |
||
| 58 | * @var string|null |
||
| 59 | */ |
||
| 60 | private $displayText2; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Entry barrier closed. |
||
| 64 | * |
||
| 65 | * @var bool|null |
||
| 66 | */ |
||
| 67 | private $entryBarrierClosed; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Exit barrier closed. |
||
| 71 | * |
||
| 72 | * @var bool|null |
||
| 73 | */ |
||
| 74 | private $exitBarrierClosed; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Expires. |
||
| 78 | * |
||
| 79 | * @var DateTime|null |
||
| 80 | */ |
||
| 81 | private $expires; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Is neutral. |
||
| 85 | * |
||
| 86 | * @var bool|null |
||
| 87 | */ |
||
| 88 | private $isNeutral; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Personal no. |
||
| 92 | * |
||
| 93 | * @var int|null |
||
| 94 | */ |
||
| 95 | private $personalNo; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Production counter. |
||
| 99 | * |
||
| 100 | * @var int|null |
||
| 101 | */ |
||
| 102 | private $productionCounter; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Production facility number. |
||
| 106 | * |
||
| 107 | * @var int|null |
||
| 108 | */ |
||
| 109 | private $productionFacilityNumber; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Production state. |
||
| 113 | * |
||
| 114 | * @var int|null |
||
| 115 | */ |
||
| 116 | private $productionState; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Reason for production. |
||
| 120 | * |
||
| 121 | * @var int|null |
||
| 122 | */ |
||
| 123 | private $reasonProduction; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Residual value. |
||
| 127 | * |
||
| 128 | * @var int|null |
||
| 129 | */ |
||
| 130 | private $residualValue; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Retain ticket at entry. |
||
| 134 | * |
||
| 135 | * @var bool|null |
||
| 136 | */ |
||
| 137 | private $retainTicketEntry; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Retain ticket at exit. |
||
| 141 | * |
||
| 142 | * @var bool|null |
||
| 143 | */ |
||
| 144 | private $retainTicketExit; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Serial no. |
||
| 148 | * |
||
| 149 | * @var string|null |
||
| 150 | */ |
||
| 151 | private $serialNo; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Serial number KeyCard/Swatch. |
||
| 155 | * |
||
| 156 | * @var string|null |
||
| 157 | */ |
||
| 158 | private $serialNumberKeyCardSwatch; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Suspend period from. |
||
| 162 | * |
||
| 163 | * @var DateTime|null |
||
| 164 | */ |
||
| 165 | private $suspendPeriodFrom; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Suspend period until. |
||
| 169 | * |
||
| 170 | * @var DateTime|null |
||
| 171 | */ |
||
| 172 | private $suspendPeriodUntil; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Ticket number. |
||
| 176 | * |
||
| 177 | * @var string|null |
||
| 178 | */ |
||
| 179 | private $ticketNumber; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Ticket sub type. |
||
| 183 | * |
||
| 184 | * @var string|null |
||
| 185 | */ |
||
| 186 | private $ticketSubType; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Ticket type. |
||
| 190 | * |
||
| 191 | * @var int|null |
||
| 192 | */ |
||
| 193 | private $ticketType; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Use valid car parks. |
||
| 197 | * |
||
| 198 | * @var bool|null |
||
| 199 | */ |
||
| 200 | private $useValidCarParks; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * User number. |
||
| 204 | * |
||
| 205 | * @var int|null |
||
| 206 | */ |
||
| 207 | private $userNumber; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Valid from. |
||
| 211 | * |
||
| 212 | * @var DateTime|null |
||
| 213 | */ |
||
| 214 | private $validFrom; |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Constructor. |
||
| 218 | */ |
||
| 219 | public function __construct() { |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Get the article number. |
||
| 225 | * |
||
| 226 | * @return int|null Returns the article number. |
||
| 227 | */ |
||
| 228 | public function getArticleNumber(): ?int { |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Get the currency residual value. |
||
| 234 | * |
||
| 235 | * @return string|null Returns the currency residual value. |
||
| 236 | */ |
||
| 237 | public function getCurrencyResidualValue(): ?string { |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Get the display text. |
||
| 243 | * |
||
| 244 | * @return bool|null Returns the display text. |
||
| 245 | */ |
||
| 246 | public function getDisplayText(): ?bool { |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Get the display text 1. |
||
| 252 | * |
||
| 253 | * @return string|null Returns the display text 1. |
||
| 254 | */ |
||
| 255 | public function getDisplayText1(): ?string { |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Get the display text 2. |
||
| 261 | * |
||
| 262 | * @return string|null Returns the display text 2. |
||
| 263 | */ |
||
| 264 | public function getDisplayText2(): ?string { |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Get the entry barrier closed. |
||
| 270 | * |
||
| 271 | * @return bool|null Returns the entry barrier closed. |
||
| 272 | */ |
||
| 273 | public function getEntryBarrierClosed(): ?bool { |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Get the exit barrier closed. |
||
| 279 | * |
||
| 280 | * @return bool|null Returns the exit barrier closed. |
||
| 281 | */ |
||
| 282 | public function getExitBarrierClosed(): ?bool { |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Get the expires. |
||
| 288 | * |
||
| 289 | * @return DateTime|null Returns the expires. |
||
| 290 | */ |
||
| 291 | public function getExpires(): ?DateTime { |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Get the is neutral. |
||
| 297 | * |
||
| 298 | * @return bool|null Returns the is neutral. |
||
| 299 | */ |
||
| 300 | public function getIsNeutral(): ?bool { |
||
| 301 | return $this->isNeutral; |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Get the personal no. |
||
| 306 | * |
||
| 307 | * @return int|null Returns the personal no. |
||
| 308 | */ |
||
| 309 | public function getPersonalNo(): ?int { |
||
| 310 | return $this->personalNo; |
||
| 311 | } |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Get the production counter. |
||
| 315 | * |
||
| 316 | * @return int|null Returns the production counter. |
||
| 317 | */ |
||
| 318 | public function getProductionCounter(): ?int { |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Get the production facility number. |
||
| 324 | * |
||
| 325 | * @return int|null Returns the production facility number. |
||
| 326 | */ |
||
| 327 | public function getProductionFacilityNumber(): ?int { |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Get the production state. |
||
| 333 | * |
||
| 334 | * @return int|null Returns the production state. |
||
| 335 | */ |
||
| 336 | public function getProductionState(): ?int { |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Get the reason for production. |
||
| 342 | * |
||
| 343 | * @return int|null Returns the reason for production. |
||
| 344 | */ |
||
| 345 | public function getReasonProduction(): ?int { |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Get the residual value. |
||
| 351 | * |
||
| 352 | * @return int|null Returns the residual value. |
||
| 353 | */ |
||
| 354 | public function getResidualValue(): ?int { |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Get the retain ticket at entry. |
||
| 360 | * |
||
| 361 | * @return bool|null Returns the retain ticket at entry. |
||
| 362 | */ |
||
| 363 | public function getRetainTicketEntry(): ?bool { |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Get the retain ticket exit. |
||
| 369 | * |
||
| 370 | * @return bool|null Returns the retain ticket ax exit. |
||
| 371 | */ |
||
| 372 | public function getRetainTicketExit(): ?bool { |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Get the serial no. |
||
| 378 | * |
||
| 379 | * @return string|null Returns the serial no. |
||
| 380 | */ |
||
| 381 | public function getSerialNo(): ?string { |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Get the serial number KeyCard/Swatch. |
||
| 387 | * |
||
| 388 | * @return string|null Returns the serial number KeyCard/Swatch. |
||
| 389 | */ |
||
| 390 | public function getSerialNumberKeyCardSwatch(): ?string { |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Get the suspend period from. |
||
| 396 | * |
||
| 397 | * @return DateTime|null Returns the suspend period from. |
||
| 398 | */ |
||
| 399 | public function getSuspendPeriodFrom(): ?DateTime { |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Get the suspend period until. |
||
| 405 | * |
||
| 406 | * @return DateTime|null Returns the suspend period until. |
||
| 407 | */ |
||
| 408 | public function getSuspendPeriodUntil(): ?DateTime { |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Get the ticket number. |
||
| 414 | * |
||
| 415 | * @return string|null Returns the ticket number. |
||
| 416 | */ |
||
| 417 | public function getTicketNumber(): ?string { |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Get the ticket sub type. |
||
| 423 | * |
||
| 424 | * @return string|null Returns the ticket sub type. |
||
| 425 | */ |
||
| 426 | public function getTicketSubType(): ?string { |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Get the ticket type. |
||
| 432 | * |
||
| 433 | * @return int|null Returns the ticket type. |
||
| 434 | */ |
||
| 435 | public function getTicketType(): ?int { |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Get the use valid car parks. |
||
| 441 | * |
||
| 442 | * @return bool|null Returns the use valid car parks. |
||
| 443 | */ |
||
| 444 | public function getUseValidCarParks(): ?bool { |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Get the user number. |
||
| 450 | * |
||
| 451 | * @return int|null Returns the user number. |
||
| 452 | */ |
||
| 453 | public function getUserNumber(): ?int { |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Get the valid from. |
||
| 459 | * |
||
| 460 | * @return DateTime|null Returns the valid from. |
||
| 461 | */ |
||
| 462 | public function getValidFrom(): ?DateTime { |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Set the article number. |
||
| 468 | * |
||
| 469 | * @param int|null $articleNumber The article number. |
||
| 470 | * @return Card Returns this card. |
||
| 471 | */ |
||
| 472 | public function setArticleNumber(?int $articleNumber): Card { |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Set the currency residual value. |
||
| 479 | * |
||
| 480 | * @param string|null $currencyResidualValue The currency residual value. |
||
| 481 | * @return Card Returns this card. |
||
| 482 | */ |
||
| 483 | public function setCurrencyResidualValue(?string $currencyResidualValue): Card { |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Set the display text. |
||
| 490 | * |
||
| 491 | * @param bool|null $displayText The display text. |
||
| 492 | * @return Card Returns this card. |
||
| 493 | */ |
||
| 494 | public function setDisplayText(?bool $displayText): Card { |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Set the display text 1. |
||
| 501 | * |
||
| 502 | * @param string|null $displayText1 The display text 1. |
||
| 503 | * @return Card Returns this card. |
||
| 504 | */ |
||
| 505 | public function setDisplayText1(?string $displayText1): Card { |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Set the display text 2. |
||
| 512 | * |
||
| 513 | * @param string|null $displayText2 The display text 2. |
||
| 514 | * @return Card Returns this card. |
||
| 515 | */ |
||
| 516 | public function setDisplayText2(?string $displayText2): Card { |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Set the entry barrier closed. |
||
| 523 | * |
||
| 524 | * @param bool|null $entryBarrierClosed The entry barrier closed. |
||
| 525 | * @return Card Returns this card. |
||
| 526 | */ |
||
| 527 | public function setEntryBarrierClosed(?bool $entryBarrierClosed): Card { |
||
| 531 | |||
| 532 | /** |
||
| 533 | * Set the exit barrier closed. |
||
| 534 | * |
||
| 535 | * @param bool|null $exitBarrierClosed The exit barrier closed. |
||
| 536 | * @return Card Returns this card. |
||
| 537 | */ |
||
| 538 | public function setExitBarrierClosed(?bool $exitBarrierClosed): Card { |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Set the expires. |
||
| 545 | * |
||
| 546 | * @param DateTime|null $expires The expires. |
||
| 547 | * @return Card Returns this card. |
||
| 548 | */ |
||
| 549 | public function setExpires(?DateTime $expires): Card { |
||
| 553 | |||
| 554 | /** |
||
| 555 | * Set the is neutral. |
||
| 556 | * |
||
| 557 | * @param bool|null $isNeutral The is neutral. |
||
| 558 | * @return Card Returns this card. |
||
| 559 | */ |
||
| 560 | public function setIsNeutral(?bool $isNeutral): Card { |
||
| 561 | $this->isNeutral = $isNeutral; |
||
| 562 | return $this; |
||
| 563 | } |
||
| 564 | |||
| 565 | /** |
||
| 566 | * Set the personal no. |
||
| 567 | * |
||
| 568 | * @param int|null $personalNo The personal no. |
||
| 569 | * @return Card Returns this card. |
||
| 570 | */ |
||
| 571 | public function setPersonalNo(?int $personalNo): Card { |
||
| 572 | $this->personalNo = $personalNo; |
||
| 573 | return $this; |
||
| 574 | } |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Set the production counter. |
||
| 578 | * |
||
| 579 | * @param int|null $productionCounter The production counter. |
||
| 580 | * @return Card Returns this card. |
||
| 581 | */ |
||
| 582 | public function setProductionCounter(?int $productionCounter): Card { |
||
| 586 | |||
| 587 | /** |
||
| 588 | * Set the production facility number. |
||
| 589 | * |
||
| 590 | * @param int|null $productionFacilityNumber The production facility number. |
||
| 591 | * @return Card Returns this card. |
||
| 592 | */ |
||
| 593 | public function setProductionFacilityNumber(?int $productionFacilityNumber): Card { |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Set the production state. |
||
| 600 | * |
||
| 601 | * @param int|null $productionState The production state. |
||
| 602 | * @return Card Returns this card. |
||
| 603 | */ |
||
| 604 | public function setProductionState(?int $productionState): Card { |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Set the reason for production. |
||
| 611 | * |
||
| 612 | * @param int|null $reasonProduction The reason for production. |
||
| 613 | * @return Card Returns this card. |
||
| 614 | */ |
||
| 615 | public function setReasonProduction(?int $reasonProduction): Card { |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Set the residual value. |
||
| 622 | * |
||
| 623 | * @param int|null $residualValue The residual value. |
||
| 624 | * @return Card Returns this card. |
||
| 625 | */ |
||
| 626 | public function setResidualValue(?int $residualValue): Card { |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Set the retain ticket at entry. |
||
| 633 | * |
||
| 634 | * @param bool|null $retainTicketEntry The retain ticket at entry. |
||
| 635 | * @return Card Returns this card. |
||
| 636 | */ |
||
| 637 | public function setRetainTicketEntry(?bool $retainTicketEntry): Card { |
||
| 641 | |||
| 642 | /** |
||
| 643 | * Set the retain ticket at exit. |
||
| 644 | * |
||
| 645 | * @param bool|null $retainTicketExit The retain ticket at exit. |
||
| 646 | * @return Card Returns this card. |
||
| 647 | */ |
||
| 648 | public function setRetainTicketExit(?bool $retainTicketExit): Card { |
||
| 652 | |||
| 653 | /** |
||
| 654 | * Set the serial no. |
||
| 655 | * |
||
| 656 | * @param string|null $serialNo The serial no. |
||
| 657 | * @return Card Returns this card. |
||
| 658 | */ |
||
| 659 | public function setSerialNo(?string $serialNo): Card { |
||
| 663 | |||
| 664 | /** |
||
| 665 | * Set the serial number KeyCard/Swatch. |
||
| 666 | * |
||
| 667 | * @param string|null $serialNumberKeyCardSwatch The serial number KeyCard/Swatch. |
||
| 668 | * @return Card Returns this card. |
||
| 669 | */ |
||
| 670 | public function setSerialNumberKeyCardSwatch(?string $serialNumberKeyCardSwatch): Card { |
||
| 674 | |||
| 675 | /** |
||
| 676 | * Set the suspend period from. |
||
| 677 | * |
||
| 678 | * @param DateTime|null $suspendPeriodFrom The suspend period from. |
||
| 679 | * @return Card Returns this card. |
||
| 680 | */ |
||
| 681 | public function setSuspendPeriodFrom(?DateTime $suspendPeriodFrom): Card { |
||
| 685 | |||
| 686 | /** |
||
| 687 | * Set the suspend period until. |
||
| 688 | * |
||
| 689 | * @param DateTime|null $suspendPeriodUntil The suspend period until. |
||
| 690 | * @return Card Returns this card. |
||
| 691 | */ |
||
| 692 | public function setSuspendPeriodUntil(?DateTime $suspendPeriodUntil): Card { |
||
| 696 | |||
| 697 | /** |
||
| 698 | * Set the ticket number. |
||
| 699 | * |
||
| 700 | * @param string|null $ticketNumber The ticket number. |
||
| 701 | * @return Card Returns this card. |
||
| 702 | */ |
||
| 703 | public function setTicketNumber(?string $ticketNumber): Card { |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Set the ticket sub type. |
||
| 710 | * |
||
| 711 | * @param string|null $ticketSubType The ticket sub type. |
||
| 712 | * @return Card Returns this card. |
||
| 713 | */ |
||
| 714 | public function setTicketSubType(?string $ticketSubType): Card { |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Set the ticket type. |
||
| 721 | * |
||
| 722 | * @param int|null $ticketType The ticket type. |
||
| 723 | * @return Card Returns this card. |
||
| 724 | */ |
||
| 725 | public function setTicketType(?int $ticketType): Card { |
||
| 729 | |||
| 730 | /** |
||
| 731 | * Set the use valid car parks. |
||
| 732 | * |
||
| 733 | * @param bool|null $useValidCarParks The use valid car parks. |
||
| 734 | * @return Card Returns this card. |
||
| 735 | */ |
||
| 736 | public function setUseValidCarParks(?bool $useValidCarParks): Card { |
||
| 740 | |||
| 741 | /** |
||
| 742 | * Set the user number. |
||
| 743 | * |
||
| 744 | * @param int|null $userNumber The user number. |
||
| 745 | * @return Card Returns this card. |
||
| 746 | */ |
||
| 747 | public function setUserNumber(?int $userNumber): Card { |
||
| 751 | |||
| 752 | /** |
||
| 753 | * Set the valid from. |
||
| 754 | * |
||
| 755 | * @param DateTime|null $validFrom The valid from. |
||
| 756 | * @return Card Returns this card. |
||
| 757 | */ |
||
| 758 | public function setValidFrom(?DateTime $validFrom): Card { |
||
| 762 | } |
||
| 763 |