Complex classes like Message 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 Message, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class Message implements PayloadInterface |
||
| 14 | { |
||
| 15 | /* |
||
| 16 | * Show message directly on phone. The message is not saved on the phone. (Also known as flash messages) |
||
| 17 | */ |
||
| 18 | const CLASS_0 = 0; |
||
| 19 | |||
| 20 | /* |
||
| 21 | * Save message in phone memory. Either on the phone or in SIM. |
||
| 22 | */ |
||
| 23 | const CLASS_1 = 1; |
||
| 24 | |||
| 25 | /* |
||
| 26 | * Message contains SIM data. |
||
| 27 | */ |
||
| 28 | const CLASS_2 = 2; |
||
| 29 | |||
| 30 | /* |
||
| 31 | * Message contains info that indicate that it should be |
||
| 32 | * sent to external units, normally used by terminal equipment. |
||
| 33 | */ |
||
| 34 | const CLASS_3 = 3; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Note! These content types currently only apply to danish shortcodes |
||
| 38 | * See https://linkmobility.atlassian.net/wiki/display/COOL/14.+Contenttypes for more info |
||
| 39 | */ |
||
| 40 | const CONTENT_TYPE_1 = 1; // Ringetoner og billeder |
||
| 41 | const CONTENT_TYPE_2 = 2; // Videoklip og tv |
||
| 42 | const CONTENT_TYPE_3 = 3; // Voksenindhold |
||
| 43 | const CONTENT_TYPE_4 = 4; // Musik |
||
| 44 | const CONTENT_TYPE_5 = 5; // Lydbøger og podcasts |
||
| 45 | const CONTENT_TYPE_6 = 6; // Mobilspil |
||
| 46 | const CONTENT_TYPE_7 = 7; // Chat tjenester |
||
| 47 | const CONTENT_TYPE_8 = 8; // Konkurrence og afstemning |
||
| 48 | const CONTENT_TYPE_9 = 9; // M-payment (Fysik varer) |
||
| 49 | const CONTENT_TYPE_10 = 10; // Nyheder og information |
||
| 50 | const CONTENT_TYPE_11 = 11; // Indsamlinger / donationer (Humanitære organisationer) |
||
| 51 | const CONTENT_TYPE_12 = 12; // Telemetri (M2M) |
||
| 52 | const CONTENT_TYPE_13 = 13; // Diverse |
||
| 53 | const CONTENT_TYPE_14 = 14; // Indsamlinger / donationer (ikke humanitære organisationer) |
||
| 54 | const CONTENT_TYPE_15 = 15; // Lotteri (moms fri) |
||
| 55 | |||
| 56 | /* |
||
| 57 | * Send normal message (160 chars, but if more than 160 chars, 153 chars per part message) |
||
| 58 | */ |
||
| 59 | const FORMAT_GSM = 'GSM'; |
||
| 60 | |||
| 61 | /* |
||
| 62 | * To send speciality chars like chinese letters. A normal message is 160 chars, but ifyou use |
||
| 63 | * unicode each message can only hold 70 chars (But if more than 70 chars, 67 chars per part message) |
||
| 64 | */ |
||
| 65 | const FORMAT_UNICODE = 'UNICODE'; |
||
| 66 | |||
| 67 | /* |
||
| 68 | * Send a binary message body in hex and define udh |
||
| 69 | */ |
||
| 70 | const FORMAT_BINARY = 'BINARY'; |
||
| 71 | |||
| 72 | /* |
||
| 73 | * Send a link that is opened on the phone |
||
| 74 | */ |
||
| 75 | const FORMAT_WAPPUSH = 'WAPPUSH'; |
||
| 76 | |||
| 77 | /* |
||
| 78 | * Array of attachments to send as MMS To send a presentation, the first attachment |
||
| 79 | * needs to be a SMIL document with the extension .smil Sender should be a valid shortcode |
||
| 80 | */ |
||
| 81 | const FORMAT_MMS = 'MMS'; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var array |
||
| 85 | */ |
||
| 86 | protected $recipients; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var string |
||
| 90 | */ |
||
| 91 | protected $sender; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var string |
||
| 95 | */ |
||
| 96 | protected $message; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var boolean |
||
| 100 | */ |
||
| 101 | protected $status; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var string |
||
| 105 | */ |
||
| 106 | protected $statusUrl; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var string |
||
| 110 | */ |
||
| 111 | protected $returnData; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var int |
||
| 115 | */ |
||
| 116 | protected $class; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var \DateTimeInterface |
||
| 120 | */ |
||
| 121 | protected $sendTime; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var int |
||
| 125 | */ |
||
| 126 | protected $price; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var boolean |
||
| 130 | */ |
||
| 131 | protected $charity; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @var string |
||
| 135 | */ |
||
| 136 | protected $invoiceText; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @var int |
||
| 140 | */ |
||
| 141 | protected $validity; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var integer |
||
| 145 | */ |
||
| 146 | protected $contentType; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @var string |
||
| 150 | */ |
||
| 151 | protected $format; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var string |
||
| 155 | */ |
||
| 156 | protected $udh; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var array |
||
| 160 | */ |
||
| 161 | protected $attachment; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var string |
||
| 165 | */ |
||
| 166 | protected $pushUrl; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @var string |
||
| 170 | */ |
||
| 171 | protected $pushExpire; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var array |
||
| 175 | */ |
||
| 176 | protected $filter; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @var array |
||
| 180 | */ |
||
| 181 | protected $segmentation; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @var int |
||
| 185 | */ |
||
| 186 | protected $pid; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @var string |
||
| 190 | */ |
||
| 191 | protected $advanced; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @var string |
||
| 195 | */ |
||
| 196 | protected $protocol; |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @var string |
||
| 200 | */ |
||
| 201 | protected $revenueText; |
||
| 202 | |||
| 203 | public function __construct() |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @inheritdoc |
||
| 210 | */ |
||
| 211 | public function getPayload(): array |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @inheritdoc |
||
| 249 | */ |
||
| 250 | public function validate(): void |
||
| 293 | |||
| 294 | public function addRecipient($recipient) : Message |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Returns the possible classes for the payload |
||
| 302 | * |
||
| 303 | * @return array |
||
| 304 | */ |
||
| 305 | public static function getClasses() : array |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Returns the possible content types for the payload |
||
| 312 | * |
||
| 313 | * @return array |
||
| 314 | */ |
||
| 315 | public static function getContentTypes() : array |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Returns the possible formats for the payload |
||
| 338 | * |
||
| 339 | * @return array |
||
| 340 | */ |
||
| 341 | public static function getFormats() : array |
||
| 351 | |||
| 352 | /* |
||
| 353 | * Getters / Setters |
||
| 354 | */ |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @return array |
||
| 358 | */ |
||
| 359 | public function getRecipients(): array |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @param array $recipients |
||
| 366 | * @return Message |
||
| 367 | */ |
||
| 368 | public function setRecipients(array $recipients) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @return string |
||
| 376 | */ |
||
| 377 | public function getSender(): string |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @param string $sender |
||
| 384 | * @return Message |
||
| 385 | */ |
||
| 386 | public function setSender(string $sender) |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @return string |
||
| 394 | */ |
||
| 395 | public function getMessage(): string |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @param string $message |
||
| 402 | * @return Message |
||
| 403 | */ |
||
| 404 | public function setMessage(string $message) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @return bool |
||
| 412 | */ |
||
| 413 | public function isStatus(): bool |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @param bool $status |
||
| 420 | * @return Message |
||
| 421 | */ |
||
| 422 | public function setStatus(bool $status) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @return string |
||
| 430 | */ |
||
| 431 | public function getStatusUrl(): string |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @param string $statusUrl |
||
| 438 | * @return Message |
||
| 439 | */ |
||
| 440 | public function setStatusUrl(string $statusUrl) |
||
| 445 | |||
| 446 | /** |
||
| 447 | * @return string |
||
| 448 | */ |
||
| 449 | public function getReturnData(): string |
||
| 453 | |||
| 454 | /** |
||
| 455 | * @param string $returnData |
||
| 456 | * @return Message |
||
| 457 | */ |
||
| 458 | public function setReturnData(string $returnData) |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @return int |
||
| 466 | */ |
||
| 467 | public function getClass(): int |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @param int $class |
||
| 474 | * @return Message |
||
| 475 | */ |
||
| 476 | public function setClass(int $class) |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @return \DateTimeInterface |
||
| 484 | */ |
||
| 485 | public function getSendTime(): \DateTimeInterface |
||
| 489 | |||
| 490 | /** |
||
| 491 | * @param \DateTimeInterface $sendTime |
||
| 492 | * @return Message |
||
| 493 | */ |
||
| 494 | public function setSendTime(\DateTimeInterface $sendTime) |
||
| 499 | |||
| 500 | /** |
||
| 501 | * @return int |
||
| 502 | */ |
||
| 503 | public function getPrice(): int |
||
| 507 | |||
| 508 | /** |
||
| 509 | * @param int $price |
||
| 510 | * @return Message |
||
| 511 | */ |
||
| 512 | public function setPrice(int $price) |
||
| 517 | |||
| 518 | /** |
||
| 519 | * @return bool |
||
| 520 | */ |
||
| 521 | public function isCharity(): bool |
||
| 525 | |||
| 526 | /** |
||
| 527 | * @param bool $charity |
||
| 528 | * @return Message |
||
| 529 | */ |
||
| 530 | public function setCharity(bool $charity) |
||
| 535 | |||
| 536 | /** |
||
| 537 | * @return string |
||
| 538 | */ |
||
| 539 | public function getInvoiceText(): string |
||
| 543 | |||
| 544 | /** |
||
| 545 | * @param string $invoiceText |
||
| 546 | * @return Message |
||
| 547 | */ |
||
| 548 | public function setInvoiceText(string $invoiceText) |
||
| 553 | |||
| 554 | /** |
||
| 555 | * @return int |
||
| 556 | */ |
||
| 557 | public function getValidity(): int |
||
| 561 | |||
| 562 | /** |
||
| 563 | * @param int $validity |
||
| 564 | * @return Message |
||
| 565 | */ |
||
| 566 | public function setValidity(int $validity) |
||
| 571 | |||
| 572 | /** |
||
| 573 | * @return int |
||
| 574 | */ |
||
| 575 | public function getContentType(): int |
||
| 579 | |||
| 580 | /** |
||
| 581 | * @param int $contentType |
||
| 582 | * @return Message |
||
| 583 | */ |
||
| 584 | public function setContentType(int $contentType) |
||
| 589 | |||
| 590 | /** |
||
| 591 | * @return string |
||
| 592 | */ |
||
| 593 | public function getFormat(): string |
||
| 597 | |||
| 598 | /** |
||
| 599 | * @param string $format |
||
| 600 | * @return Message |
||
| 601 | */ |
||
| 602 | public function setFormat(string $format) |
||
| 607 | |||
| 608 | /** |
||
| 609 | * @return string |
||
| 610 | */ |
||
| 611 | public function getUdh(): string |
||
| 615 | |||
| 616 | /** |
||
| 617 | * @param string $udh |
||
| 618 | * @return Message |
||
| 619 | */ |
||
| 620 | public function setUdh(string $udh) |
||
| 625 | |||
| 626 | /** |
||
| 627 | * @return array |
||
| 628 | */ |
||
| 629 | public function getAttachment(): array |
||
| 633 | |||
| 634 | /** |
||
| 635 | * @param array $attachment |
||
| 636 | * @return Message |
||
| 637 | */ |
||
| 638 | public function setAttachment(array $attachment) |
||
| 643 | |||
| 644 | /** |
||
| 645 | * @return string |
||
| 646 | */ |
||
| 647 | public function getPushUrl(): string |
||
| 651 | |||
| 652 | /** |
||
| 653 | * @param string $pushUrl |
||
| 654 | * @return Message |
||
| 655 | */ |
||
| 656 | public function setPushUrl(string $pushUrl) |
||
| 661 | |||
| 662 | /** |
||
| 663 | * @return string |
||
| 664 | */ |
||
| 665 | public function getPushExpire(): string |
||
| 669 | |||
| 670 | /** |
||
| 671 | * @param string $pushExpire |
||
| 672 | * @return Message |
||
| 673 | */ |
||
| 674 | public function setPushExpire(string $pushExpire) |
||
| 679 | |||
| 680 | /** |
||
| 681 | * @return array |
||
| 682 | */ |
||
| 683 | public function getFilter(): array |
||
| 687 | |||
| 688 | /** |
||
| 689 | * @param array $filter |
||
| 690 | * @return Message |
||
| 691 | */ |
||
| 692 | public function setFilter(array $filter) |
||
| 697 | |||
| 698 | /** |
||
| 699 | * @return array |
||
| 700 | */ |
||
| 701 | public function getSegmentation(): array |
||
| 705 | |||
| 706 | /** |
||
| 707 | * @param array $segmentation |
||
| 708 | * @return Message |
||
| 709 | */ |
||
| 710 | public function setSegmentation(array $segmentation) |
||
| 715 | |||
| 716 | /** |
||
| 717 | * @return int |
||
| 718 | */ |
||
| 719 | public function getPid(): int |
||
| 723 | |||
| 724 | /** |
||
| 725 | * @param int $pid |
||
| 726 | * @return Message |
||
| 727 | */ |
||
| 728 | public function setPid(int $pid) |
||
| 733 | |||
| 734 | /** |
||
| 735 | * @return string |
||
| 736 | */ |
||
| 737 | public function getAdvanced(): string |
||
| 741 | |||
| 742 | /** |
||
| 743 | * @param string $advanced |
||
| 744 | * @return Message |
||
| 745 | */ |
||
| 746 | public function setAdvanced(string $advanced) |
||
| 751 | |||
| 752 | /** |
||
| 753 | * @return string |
||
| 754 | */ |
||
| 755 | public function getProtocol(): string |
||
| 759 | |||
| 760 | /** |
||
| 761 | * @param string $protocol |
||
| 762 | * @return Message |
||
| 763 | */ |
||
| 764 | public function setProtocol(string $protocol) |
||
| 769 | |||
| 770 | /** |
||
| 771 | * @return string |
||
| 772 | */ |
||
| 773 | public function getRevenueText(): string |
||
| 777 | |||
| 778 | /** |
||
| 779 | * @param string $revenueText |
||
| 780 | * @return Message |
||
| 781 | */ |
||
| 782 | public function setRevenueText(string $revenueText) |
||
| 787 | } |
||
| 788 |