Complex classes like EventData 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 EventData, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class EventData implements CreatableFromArray |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | private $invoiceNo; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | private $deliveryMethod; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $letterId; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var int |
||
| 31 | */ |
||
| 32 | private $amount; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | private $payerName; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var array |
||
| 41 | */ |
||
| 42 | private $paymentFlags = []; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var int |
||
| 46 | */ |
||
| 47 | private $bankingAmount; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var bool |
||
| 51 | */ |
||
| 52 | private $manual; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var int |
||
| 56 | */ |
||
| 57 | private $reminderFee; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var int |
||
| 61 | */ |
||
| 62 | private $reminderCount; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var int |
||
| 66 | */ |
||
| 67 | private $interestRate; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | private $customerEmail; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var string |
||
| 76 | */ |
||
| 77 | private $customerPhone; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | private $ip; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var string |
||
| 86 | */ |
||
| 87 | private $type; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string[] |
||
| 91 | */ |
||
| 92 | private $message; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | private $fullStatus; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | private $collectorMethod; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var string |
||
| 106 | */ |
||
| 107 | private $collectorReference; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var string |
||
| 111 | */ |
||
| 112 | private $factoringMethod; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var string |
||
| 116 | */ |
||
| 117 | private $factoringReference; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var int |
||
| 121 | */ |
||
| 122 | private $sellsFor; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @var int |
||
| 126 | */ |
||
| 127 | private $soldFor; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @var string |
||
| 131 | */ |
||
| 132 | private $bankgiro; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @var string |
||
| 136 | */ |
||
| 137 | private $recipientIdentifier; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @var string |
||
| 141 | */ |
||
| 142 | private $errorStatus; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @var int |
||
| 146 | */ |
||
| 147 | private $totalSum; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @var int |
||
| 151 | */ |
||
| 152 | private $remainingSum; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @var bool |
||
| 156 | */ |
||
| 157 | private $scanningCentral; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @return string |
||
| 161 | */ |
||
| 162 | public function getInvoiceNo(): string |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @param string $invoiceNo |
||
| 169 | * |
||
| 170 | * @return EventData |
||
| 171 | */ |
||
| 172 | public function withInvoiceNo(string $invoiceNo) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @return string |
||
| 182 | */ |
||
| 183 | public function getDeliveryMethod(): string |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param string $deliveryMethod |
||
| 190 | * |
||
| 191 | * @return EventData |
||
| 192 | */ |
||
| 193 | public function withDeliveryMethod(string $deliveryMethod) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | public function getLetterId(): string |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @param string $letterId |
||
| 211 | * |
||
| 212 | * @return EventData |
||
| 213 | */ |
||
| 214 | public function withLetterId(string $letterId) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @return int |
||
| 224 | */ |
||
| 225 | public function getAmount(): int |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @param int $amount |
||
| 232 | * |
||
| 233 | * @return EventData |
||
| 234 | */ |
||
| 235 | public function withAmount(int $amount) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @return string |
||
| 245 | */ |
||
| 246 | public function getPayerName(): string |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @param string $payerName |
||
| 253 | * |
||
| 254 | * @return EventData |
||
| 255 | */ |
||
| 256 | public function withPayerName(string $payerName) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @return array |
||
| 266 | */ |
||
| 267 | public function getPaymentFlags(): array |
||
| 271 | |||
| 272 | /** |
||
| 273 | * @param array $paymentFlags |
||
| 274 | * |
||
| 275 | * @return EventData |
||
| 276 | */ |
||
| 277 | public function withPaymentFlags(array $paymentFlags) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @return int |
||
| 287 | */ |
||
| 288 | public function getBankingAmount(): int |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @param int $bankingAmount |
||
| 295 | * |
||
| 296 | * @return EventData |
||
| 297 | */ |
||
| 298 | public function withBankingAmount(int $bankingAmount) |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @return bool |
||
| 308 | */ |
||
| 309 | public function isManual(): bool |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param bool $manual |
||
| 316 | * |
||
| 317 | * @return EventData |
||
| 318 | */ |
||
| 319 | public function withManual(bool $manual) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @return int |
||
| 329 | */ |
||
| 330 | public function getReminderFee(): int |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @param int $reminderFee |
||
| 337 | * |
||
| 338 | * @return EventData |
||
| 339 | */ |
||
| 340 | public function withReminderFee(int $reminderFee) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @return int |
||
| 350 | */ |
||
| 351 | public function getReminderCount(): int |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @param int $reminderCount |
||
| 358 | * |
||
| 359 | * @return EventData |
||
| 360 | */ |
||
| 361 | public function withReminderCount(int $reminderCount) |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @return int |
||
| 371 | */ |
||
| 372 | public function getInterestRate(): int |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @param int $interestRate |
||
| 379 | * |
||
| 380 | * @return EventData |
||
| 381 | */ |
||
| 382 | public function withInterestRate(int $interestRate) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @return string |
||
| 392 | */ |
||
| 393 | public function getCustomerEmail(): string |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @param string $customerEmail |
||
| 400 | * |
||
| 401 | * @return EventData |
||
| 402 | */ |
||
| 403 | public function withCustomerEmail(string $customerEmail) |
||
| 410 | |||
| 411 | /** |
||
| 412 | * @return string |
||
| 413 | */ |
||
| 414 | public function getCustomerPhone(): string |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @param string $customerPhone |
||
| 421 | * |
||
| 422 | * @return EventData |
||
| 423 | */ |
||
| 424 | public function withCustomerPhone(string $customerPhone) |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @return string |
||
| 434 | */ |
||
| 435 | public function getIp(): string |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @param string $ip |
||
| 442 | * |
||
| 443 | * @return EventData |
||
| 444 | */ |
||
| 445 | public function withIp(string $ip) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @return string |
||
| 455 | */ |
||
| 456 | public function getType(): string |
||
| 460 | |||
| 461 | /** |
||
| 462 | * @param string $type |
||
| 463 | * |
||
| 464 | * @return EventData |
||
| 465 | */ |
||
| 466 | public function withType(string $type) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @return \string[] |
||
| 476 | */ |
||
| 477 | public function getMessage(): array |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @param \string[] $message |
||
| 484 | * |
||
| 485 | * @return EventData |
||
| 486 | */ |
||
| 487 | public function withMessage(array $message) |
||
| 494 | |||
| 495 | /** |
||
| 496 | * @return string |
||
| 497 | */ |
||
| 498 | public function getFullStatus(): string |
||
| 502 | |||
| 503 | /** |
||
| 504 | * @param string $fullStatus |
||
| 505 | * |
||
| 506 | * @return EventData |
||
| 507 | */ |
||
| 508 | public function withFullStatus(string $fullStatus) |
||
| 515 | |||
| 516 | /** |
||
| 517 | * @return string |
||
| 518 | */ |
||
| 519 | public function getCollectorMethod(): string |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @param string $collectorMethod |
||
| 526 | * |
||
| 527 | * @return EventData |
||
| 528 | */ |
||
| 529 | public function setCollectorMethod(string $collectorMethod) |
||
| 536 | |||
| 537 | /** |
||
| 538 | * @return string |
||
| 539 | */ |
||
| 540 | public function getCollectorReference(): string |
||
| 544 | |||
| 545 | /** |
||
| 546 | * @param string $collectorReference |
||
| 547 | * |
||
| 548 | * @return EventData |
||
| 549 | */ |
||
| 550 | public function withCollectorReference(string $collectorReference) |
||
| 557 | |||
| 558 | /** |
||
| 559 | * @return string |
||
| 560 | */ |
||
| 561 | public function getFactoringMethod(): string |
||
| 565 | |||
| 566 | /** |
||
| 567 | * @param string $factoringMethod |
||
| 568 | * |
||
| 569 | * @return EventData |
||
| 570 | */ |
||
| 571 | public function withFactoringMethod(string $factoringMethod) |
||
| 578 | |||
| 579 | /** |
||
| 580 | * @return string |
||
| 581 | */ |
||
| 582 | public function getFactoringReference(): string |
||
| 586 | |||
| 587 | /** |
||
| 588 | * @param string $factoringReference |
||
| 589 | * |
||
| 590 | * @return EventData |
||
| 591 | */ |
||
| 592 | public function withFactoringReference(string $factoringReference) |
||
| 599 | |||
| 600 | /** |
||
| 601 | * @return int |
||
| 602 | */ |
||
| 603 | public function getSellsFor(): int |
||
| 607 | |||
| 608 | /** |
||
| 609 | * @param int $sellsFor |
||
| 610 | * |
||
| 611 | * @return EventData |
||
| 612 | */ |
||
| 613 | public function withSellsFor(int $sellsFor) |
||
| 620 | |||
| 621 | /** |
||
| 622 | * @return int |
||
| 623 | */ |
||
| 624 | public function getSoldFor(): int |
||
| 628 | |||
| 629 | /** |
||
| 630 | * @param int $soldFor |
||
| 631 | * |
||
| 632 | * @return EventData |
||
| 633 | */ |
||
| 634 | public function withSoldFor(int $soldFor) |
||
| 641 | |||
| 642 | /** |
||
| 643 | * @return string |
||
| 644 | */ |
||
| 645 | public function getBankgiro(): string |
||
| 649 | |||
| 650 | /** |
||
| 651 | * @param string $bankgiro |
||
| 652 | * |
||
| 653 | * @return EventData |
||
| 654 | */ |
||
| 655 | public function withBankgiro(string $bankgiro) |
||
| 662 | |||
| 663 | /** |
||
| 664 | * @return string |
||
| 665 | */ |
||
| 666 | public function getRecipientIdentifier(): string |
||
| 670 | |||
| 671 | /** |
||
| 672 | * @param string $recipientIdentifier |
||
| 673 | * |
||
| 674 | * @return EventData |
||
| 675 | */ |
||
| 676 | public function withRecipientIdentifier(string $recipientIdentifier) |
||
| 683 | |||
| 684 | /** |
||
| 685 | * @return string |
||
| 686 | */ |
||
| 687 | public function getErrorStatus(): string |
||
| 691 | |||
| 692 | /** |
||
| 693 | * @param string $errorStatus |
||
| 694 | * |
||
| 695 | * @return EventData |
||
| 696 | */ |
||
| 697 | public function withErrorStatus(string $errorStatus) |
||
| 704 | |||
| 705 | /** |
||
| 706 | * @return int |
||
| 707 | */ |
||
| 708 | public function getTotalSum(): int |
||
| 712 | |||
| 713 | /** |
||
| 714 | * @param int $totalSum |
||
| 715 | * |
||
| 716 | * @return EventData |
||
| 717 | */ |
||
| 718 | public function withTotalSum(int $totalSum) |
||
| 725 | |||
| 726 | /** |
||
| 727 | * @return int |
||
| 728 | */ |
||
| 729 | public function getRemainingSum(): int |
||
| 733 | |||
| 734 | /** |
||
| 735 | * @param int $remainingSum |
||
| 736 | * |
||
| 737 | * @return EventData |
||
| 738 | */ |
||
| 739 | public function withRemainingSum(int $remainingSum) |
||
| 746 | |||
| 747 | /** |
||
| 748 | * @return mixed |
||
| 749 | */ |
||
| 750 | public function getScanningCentral() |
||
| 754 | |||
| 755 | /** |
||
| 756 | * @param bool $scanningCentral |
||
| 757 | * |
||
| 758 | * @return EventData |
||
| 759 | */ |
||
| 760 | public function withScanningCentral(bool $scanningCentral) |
||
| 767 | |||
| 768 | public function toArray() |
||
| 858 | |||
| 859 | /** |
||
| 860 | * Create an API response object from the HTTP response from the API server. |
||
| 861 | * |
||
| 862 | * @param array $data |
||
| 863 | * |
||
| 864 | * @return self |
||
| 865 | */ |
||
| 866 | public static function createFromArray(array $data = null) |
||
| 900 | } |
||
| 901 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..