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 |
||
14 | class Message implements PayloadInterface |
||
15 | { |
||
16 | /* |
||
17 | * Show message directly on phone. The message is not saved on the phone. (Also known as flash messages) |
||
18 | */ |
||
19 | const CLASS_0 = 0; |
||
20 | |||
21 | /* |
||
22 | * Save message in phone memory. Either on the phone or in SIM. |
||
23 | */ |
||
24 | const CLASS_1 = 1; |
||
25 | |||
26 | /* |
||
27 | * Message contains SIM data. |
||
28 | */ |
||
29 | const CLASS_2 = 2; |
||
30 | |||
31 | /* |
||
32 | * Message contains info that indicate that it should be |
||
33 | * sent to external units, normally used by terminal equipment. |
||
34 | */ |
||
35 | const CLASS_3 = 3; |
||
36 | |||
37 | /** |
||
38 | * Note! These content types currently only apply to danish shortcodes |
||
39 | * See https://linkmobility.atlassian.net/wiki/display/COOL/14.+Contenttypes for more info |
||
40 | */ |
||
41 | const CONTENT_TYPE_1 = 1; // Ringetoner og billeder |
||
42 | const CONTENT_TYPE_2 = 2; // Videoklip og tv |
||
43 | const CONTENT_TYPE_3 = 3; // Voksenindhold |
||
44 | const CONTENT_TYPE_4 = 4; // Musik |
||
45 | const CONTENT_TYPE_5 = 5; // Lydbøger og podcasts |
||
46 | const CONTENT_TYPE_6 = 6; // Mobilspil |
||
47 | const CONTENT_TYPE_7 = 7; // Chat tjenester |
||
48 | const CONTENT_TYPE_8 = 8; // Konkurrence og afstemning |
||
49 | const CONTENT_TYPE_9 = 9; // M-payment (Fysik varer) |
||
50 | const CONTENT_TYPE_10 = 10; // Nyheder og information |
||
51 | const CONTENT_TYPE_11 = 11; // Indsamlinger / donationer (Humanitære organisationer) |
||
52 | const CONTENT_TYPE_12 = 12; // Telemetri (M2M) |
||
53 | const CONTENT_TYPE_13 = 13; // Diverse |
||
54 | const CONTENT_TYPE_14 = 14; // Indsamlinger / donationer (ikke humanitære organisationer) |
||
55 | const CONTENT_TYPE_15 = 15; // Lotteri (moms fri) |
||
56 | |||
57 | /* |
||
58 | * Send normal message (160 chars, but if more than 160 chars, 153 chars per part message) |
||
59 | */ |
||
60 | const FORMAT_GSM = 'GSM'; |
||
61 | |||
62 | /* |
||
63 | * To send speciality chars like chinese letters. A normal message is 160 chars, but ifyou use |
||
64 | * unicode each message can only hold 70 chars (But if more than 70 chars, 67 chars per part message) |
||
65 | */ |
||
66 | const FORMAT_UNICODE = 'UNICODE'; |
||
67 | |||
68 | /* |
||
69 | * Send a binary message body in hex and define udh |
||
70 | */ |
||
71 | const FORMAT_BINARY = 'BINARY'; |
||
72 | |||
73 | /* |
||
74 | * Send a link that is opened on the phone |
||
75 | */ |
||
76 | const FORMAT_WAPPUSH = 'WAPPUSH'; |
||
77 | |||
78 | /* |
||
79 | * Array of attachments to send as MMS To send a presentation, the first attachment |
||
80 | * needs to be a SMIL document with the extension .smil Sender should be a valid shortcode |
||
81 | */ |
||
82 | const FORMAT_MMS = 'MMS'; |
||
83 | |||
84 | /** |
||
85 | * @var array |
||
86 | */ |
||
87 | protected $recipients; |
||
88 | |||
89 | /** |
||
90 | * @var string |
||
91 | */ |
||
92 | protected $sender; |
||
93 | |||
94 | /** |
||
95 | * @var string |
||
96 | */ |
||
97 | protected $message; |
||
98 | |||
99 | /** |
||
100 | * @var boolean |
||
101 | */ |
||
102 | protected $status; |
||
103 | |||
104 | /** |
||
105 | * @var string |
||
106 | */ |
||
107 | protected $statusUrl; |
||
108 | |||
109 | /** |
||
110 | * @var string |
||
111 | */ |
||
112 | protected $returnData; |
||
113 | |||
114 | /** |
||
115 | * @var int |
||
116 | */ |
||
117 | protected $class; |
||
118 | |||
119 | /** |
||
120 | * @var \DateTimeInterface |
||
121 | */ |
||
122 | protected $sendTime; |
||
123 | |||
124 | /** |
||
125 | * @var int |
||
126 | */ |
||
127 | protected $price; |
||
128 | |||
129 | /** |
||
130 | * @var boolean |
||
131 | */ |
||
132 | protected $charity; |
||
133 | |||
134 | /** |
||
135 | * @var string |
||
136 | */ |
||
137 | protected $invoiceText; |
||
138 | |||
139 | /** |
||
140 | * @var int |
||
141 | */ |
||
142 | protected $validity; |
||
143 | |||
144 | /** |
||
145 | * @var integer |
||
146 | */ |
||
147 | protected $contentType; |
||
148 | |||
149 | /** |
||
150 | * @var string |
||
151 | */ |
||
152 | protected $format; |
||
153 | |||
154 | /** |
||
155 | * @var string |
||
156 | */ |
||
157 | protected $udh; |
||
158 | |||
159 | /** |
||
160 | * @var array |
||
161 | */ |
||
162 | protected $attachment; |
||
163 | |||
164 | /** |
||
165 | * @var string |
||
166 | */ |
||
167 | protected $pushUrl; |
||
168 | |||
169 | /** |
||
170 | * @var string |
||
171 | */ |
||
172 | protected $pushExpire; |
||
173 | |||
174 | /** |
||
175 | * @var array |
||
176 | */ |
||
177 | protected $filter; |
||
178 | |||
179 | /** |
||
180 | * @var array |
||
181 | */ |
||
182 | protected $segmentation; |
||
183 | |||
184 | /** |
||
185 | * @var int |
||
186 | */ |
||
187 | protected $pid; |
||
188 | |||
189 | /** |
||
190 | * @var string |
||
191 | */ |
||
192 | protected $advanced; |
||
193 | |||
194 | /** |
||
195 | * @var string |
||
196 | */ |
||
197 | protected $protocol; |
||
198 | |||
199 | /** |
||
200 | * @var string |
||
201 | */ |
||
202 | protected $revenueText; |
||
203 | |||
204 | public function __construct() |
||
208 | |||
209 | public static function create(string $sender, string $message, array $recipients) { |
||
218 | |||
219 | /** |
||
220 | * @inheritdoc |
||
221 | */ |
||
222 | public function getPayload(): array |
||
263 | |||
264 | /** |
||
265 | * @inheritdoc |
||
266 | */ |
||
267 | public function validate(): void |
||
309 | |||
310 | public function addRecipient($recipient) : Message |
||
315 | |||
316 | public function getChunkCount() : int |
||
320 | |||
321 | /** |
||
322 | * Returns the possible classes for the payload |
||
323 | * |
||
324 | * @return array |
||
325 | */ |
||
326 | public static function getClasses() : array |
||
330 | |||
331 | /** |
||
332 | * Returns the possible content types for the payload |
||
333 | * |
||
334 | * @return array |
||
335 | */ |
||
336 | public static function getContentTypes() : array |
||
356 | |||
357 | /** |
||
358 | * Returns the possible formats for the payload |
||
359 | * |
||
360 | * @return array |
||
361 | */ |
||
362 | public static function getFormats() : array |
||
372 | |||
373 | /* |
||
374 | * Getters / Setters |
||
375 | */ |
||
376 | |||
377 | /** |
||
378 | * @return array |
||
379 | */ |
||
380 | public function getRecipients(): array |
||
384 | |||
385 | /** |
||
386 | * @param array $recipients |
||
387 | * @return Message |
||
388 | */ |
||
389 | public function setRecipients(array $recipients) |
||
394 | |||
395 | /** |
||
396 | * @return string |
||
397 | */ |
||
398 | public function getSender(): string |
||
402 | |||
403 | /** |
||
404 | * @param string $sender |
||
405 | * @return Message |
||
406 | */ |
||
407 | public function setSender(string $sender) |
||
412 | |||
413 | /** |
||
414 | * @return string |
||
415 | */ |
||
416 | public function getMessage(): string |
||
420 | |||
421 | /** |
||
422 | * @param string $message |
||
423 | * @return Message |
||
424 | */ |
||
425 | public function setMessage(string $message) |
||
430 | |||
431 | /** |
||
432 | * @return bool |
||
433 | */ |
||
434 | public function isStatus(): bool |
||
438 | |||
439 | /** |
||
440 | * @param bool $status |
||
441 | * @return Message |
||
442 | */ |
||
443 | public function setStatus(bool $status) |
||
448 | |||
449 | /** |
||
450 | * @return string |
||
451 | */ |
||
452 | public function getStatusUrl(): string |
||
456 | |||
457 | /** |
||
458 | * @param string $statusUrl |
||
459 | * @return Message |
||
460 | */ |
||
461 | public function setStatusUrl(string $statusUrl) |
||
466 | |||
467 | /** |
||
468 | * @return string |
||
469 | */ |
||
470 | public function getReturnData(): string |
||
474 | |||
475 | /** |
||
476 | * @param string $returnData |
||
477 | * @return Message |
||
478 | */ |
||
479 | public function setReturnData(string $returnData) |
||
484 | |||
485 | /** |
||
486 | * @return int |
||
487 | */ |
||
488 | public function getClass(): int |
||
492 | |||
493 | /** |
||
494 | * @param int $class |
||
495 | * @return Message |
||
496 | */ |
||
497 | public function setClass(int $class) |
||
502 | |||
503 | /** |
||
504 | * @return \DateTimeInterface |
||
505 | */ |
||
506 | public function getSendTime(): \DateTimeInterface |
||
510 | |||
511 | /** |
||
512 | * @param \DateTimeInterface $sendTime |
||
513 | * @return Message |
||
514 | */ |
||
515 | public function setSendTime(\DateTimeInterface $sendTime) |
||
520 | |||
521 | /** |
||
522 | * @return int |
||
523 | */ |
||
524 | public function getPrice(): int |
||
528 | |||
529 | /** |
||
530 | * @param int $price |
||
531 | * @return Message |
||
532 | */ |
||
533 | public function setPrice(int $price) |
||
538 | |||
539 | /** |
||
540 | * @return bool |
||
541 | */ |
||
542 | public function isCharity(): bool |
||
546 | |||
547 | /** |
||
548 | * @param bool $charity |
||
549 | * @return Message |
||
550 | */ |
||
551 | public function setCharity(bool $charity) |
||
556 | |||
557 | /** |
||
558 | * @return string |
||
559 | */ |
||
560 | public function getInvoiceText(): string |
||
564 | |||
565 | /** |
||
566 | * @param string $invoiceText |
||
567 | * @return Message |
||
568 | */ |
||
569 | public function setInvoiceText(string $invoiceText) |
||
574 | |||
575 | /** |
||
576 | * @return int |
||
577 | */ |
||
578 | public function getValidity(): int |
||
582 | |||
583 | /** |
||
584 | * @param int $validity |
||
585 | * @return Message |
||
586 | */ |
||
587 | public function setValidity(int $validity) |
||
592 | |||
593 | /** |
||
594 | * @return int |
||
595 | */ |
||
596 | public function getContentType(): int |
||
600 | |||
601 | /** |
||
602 | * @param int $contentType |
||
603 | * @return Message |
||
604 | */ |
||
605 | public function setContentType(int $contentType) |
||
610 | |||
611 | /** |
||
612 | * @return string |
||
613 | */ |
||
614 | public function getFormat(): string |
||
618 | |||
619 | /** |
||
620 | * @param string $format |
||
621 | * @return Message |
||
622 | */ |
||
623 | public function setFormat(string $format) |
||
628 | |||
629 | /** |
||
630 | * @return string |
||
631 | */ |
||
632 | public function getUdh(): string |
||
636 | |||
637 | /** |
||
638 | * @param string $udh |
||
639 | * @return Message |
||
640 | */ |
||
641 | public function setUdh(string $udh) |
||
646 | |||
647 | /** |
||
648 | * @return array |
||
649 | */ |
||
650 | public function getAttachment(): array |
||
654 | |||
655 | /** |
||
656 | * @param array $attachment |
||
657 | * @return Message |
||
658 | */ |
||
659 | public function setAttachment(array $attachment) |
||
664 | |||
665 | /** |
||
666 | * @return string |
||
667 | */ |
||
668 | public function getPushUrl(): string |
||
672 | |||
673 | /** |
||
674 | * @param string $pushUrl |
||
675 | * @return Message |
||
676 | */ |
||
677 | public function setPushUrl(string $pushUrl) |
||
682 | |||
683 | /** |
||
684 | * @return string |
||
685 | */ |
||
686 | public function getPushExpire(): string |
||
690 | |||
691 | /** |
||
692 | * @param string $pushExpire |
||
693 | * @return Message |
||
694 | */ |
||
695 | public function setPushExpire(string $pushExpire) |
||
700 | |||
701 | /** |
||
702 | * @return array |
||
703 | */ |
||
704 | public function getFilter(): array |
||
708 | |||
709 | /** |
||
710 | * @param array $filter |
||
711 | * @return Message |
||
712 | */ |
||
713 | public function setFilter(array $filter) |
||
718 | |||
719 | /** |
||
720 | * @return array |
||
721 | */ |
||
722 | public function getSegmentation(): array |
||
726 | |||
727 | /** |
||
728 | * @param array $segmentation |
||
729 | * @return Message |
||
730 | */ |
||
731 | public function setSegmentation(array $segmentation) |
||
736 | |||
737 | /** |
||
738 | * @return int |
||
739 | */ |
||
740 | public function getPid(): int |
||
744 | |||
745 | /** |
||
746 | * @param int $pid |
||
747 | * @return Message |
||
748 | */ |
||
749 | public function setPid(int $pid) |
||
754 | |||
755 | /** |
||
756 | * @return string |
||
757 | */ |
||
758 | public function getAdvanced(): string |
||
762 | |||
763 | /** |
||
764 | * @param string $advanced |
||
765 | * @return Message |
||
766 | */ |
||
767 | public function setAdvanced(string $advanced) |
||
772 | |||
773 | /** |
||
774 | * @return string |
||
775 | */ |
||
776 | public function getProtocol(): string |
||
780 | |||
781 | /** |
||
782 | * @param string $protocol |
||
783 | * @return Message |
||
784 | */ |
||
785 | public function setProtocol(string $protocol) |
||
790 | |||
791 | /** |
||
792 | * @return string |
||
793 | */ |
||
794 | public function getRevenueText(): string |
||
798 | |||
799 | /** |
||
800 | * @param string $revenueText |
||
801 | * @return Message |
||
802 | */ |
||
803 | public function setRevenueText(string $revenueText) |
||
808 | } |
||
809 |