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 |
||
8 | class Message extends BaseType implements TypeInterface |
||
9 | { |
||
10 | /** |
||
11 | * {@inheritdoc} |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | static protected $requiredParams = ['message_id', 'from', 'date', 'chat']; |
||
16 | |||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | static protected $map = [ |
||
23 | 'message_id' => true, |
||
24 | 'from' => User::class, |
||
25 | 'date' => true, |
||
26 | 'chat' => Chat::class, |
||
27 | 'forward_from' => User::class, |
||
28 | 'forward_date' => true, |
||
29 | 'reply_to_message' => Message::class, |
||
30 | 'text' => true, |
||
31 | 'audio' => Audio::class, |
||
32 | 'document' => Document::class, |
||
33 | 'photo' => ArrayOfPhotoSize::class, |
||
34 | 'sticker' => Sticker::class, |
||
35 | 'video' => Video::class, |
||
36 | 'voice' => Voice::class, |
||
37 | 'caption' => true, |
||
38 | 'contact' => Contact::class, |
||
39 | 'location' => Location::class, |
||
40 | 'new_chat_participant' => User::class, |
||
41 | 'left_chat_participant' => User::class, |
||
42 | 'new_chat_title' => true, |
||
43 | 'new_chat_photo' => ArrayOfPhotoSize::class, |
||
44 | 'delete_chat_photo' => true, |
||
45 | 'group_chat_created' => true, |
||
46 | 'supergroup_chat_created' => true, |
||
47 | 'channel_chat_created' => true, |
||
48 | 'migrate_to_chat_id' => true, |
||
49 | 'migrate_from_chat_id' => true, |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * Unique message identifier |
||
54 | * |
||
55 | * @var int |
||
56 | */ |
||
57 | protected $messageId; |
||
58 | |||
59 | /** |
||
60 | * Sender |
||
61 | * |
||
62 | * @var \TelegramBot\Api\Types\User |
||
63 | */ |
||
64 | protected $from; |
||
65 | |||
66 | /** |
||
67 | * Date the message was sent in Unix time |
||
68 | * |
||
69 | * @var int |
||
70 | */ |
||
71 | protected $date; |
||
72 | |||
73 | /** |
||
74 | * Conversation the message belongs to — user in case of a private message, GroupChat in case of a group |
||
75 | * |
||
76 | * @var \TelegramBot\Api\Types\Chat |
||
77 | */ |
||
78 | protected $chat; |
||
79 | |||
80 | /** |
||
81 | * Optional. For forwarded messages, sender of the original message |
||
82 | * |
||
83 | * @var \TelegramBot\Api\Types\User |
||
84 | */ |
||
85 | protected $forwardFrom; |
||
86 | |||
87 | /** |
||
88 | * Optional. For forwarded messages, date the original message was sent in Unix time |
||
89 | * |
||
90 | * @var int |
||
91 | */ |
||
92 | protected $forwardDate; |
||
93 | |||
94 | /** |
||
95 | * Optional. For replies, the original message. Note that the Message object in this field will not contain further |
||
96 | * reply_to_message fields even if it itself is a reply. |
||
97 | * |
||
98 | * @var \TelegramBot\Api\Types\Message |
||
99 | */ |
||
100 | protected $replyToMessage; |
||
101 | |||
102 | /** |
||
103 | * Optional. For text messages, the actual UTF-8 text of the message |
||
104 | * |
||
105 | * @var string |
||
106 | */ |
||
107 | protected $text; |
||
108 | |||
109 | /** |
||
110 | * Optional. Message is an audio file, information about the file |
||
111 | * |
||
112 | * @var \TelegramBot\Api\Types\Audio |
||
113 | */ |
||
114 | protected $audio; |
||
115 | |||
116 | /** |
||
117 | * Optional. Message is a general file, information about the file |
||
118 | * |
||
119 | * @var \TelegramBot\Api\Types\Document |
||
120 | */ |
||
121 | protected $document; |
||
122 | |||
123 | /** |
||
124 | * Optional. Message is a photo, available sizes of the photo |
||
125 | * array of \TelegramBot\Api\Types\Photo |
||
126 | * |
||
127 | * @var array |
||
128 | */ |
||
129 | protected $photo; |
||
130 | |||
131 | /** |
||
132 | * Optional. Message is a sticker, information about the sticker |
||
133 | * |
||
134 | * @var \TelegramBot\Api\Types\Sticker |
||
135 | */ |
||
136 | protected $sticker; |
||
137 | |||
138 | /** |
||
139 | * Optional. Message is a video, information about the video |
||
140 | * |
||
141 | * @var \TelegramBot\Api\Types\Video |
||
142 | */ |
||
143 | protected $video; |
||
144 | |||
145 | /** |
||
146 | * Optional. Message is a voice message, information about the file |
||
147 | * |
||
148 | * @var \TelegramBot\Api\Types\Voice |
||
149 | */ |
||
150 | protected $voice; |
||
151 | |||
152 | /** |
||
153 | * Optional. Message is a shared contact, information about the contact |
||
154 | * |
||
155 | * @var \TelegramBot\Api\Types\Contact |
||
156 | */ |
||
157 | protected $contact; |
||
158 | |||
159 | /** |
||
160 | * Optional. Message is a shared location, information about the location |
||
161 | * |
||
162 | * @var \TelegramBot\Api\Types\Location |
||
163 | */ |
||
164 | protected $location; |
||
165 | |||
166 | /** |
||
167 | * Optional. A new member was added to the group, information about them (this member may be bot itself) |
||
168 | * |
||
169 | * @var \TelegramBot\Api\Types\User |
||
170 | */ |
||
171 | protected $newChatParticipant; |
||
172 | |||
173 | /** |
||
174 | * Optional. A member was removed from the group, information about them (this member may be bot itself) |
||
175 | * |
||
176 | * @var \TelegramBot\Api\Types\User |
||
177 | */ |
||
178 | protected $leftChatParticipant; |
||
179 | |||
180 | /** |
||
181 | * Optional. A group title was changed to this value |
||
182 | * |
||
183 | * @var string |
||
184 | */ |
||
185 | protected $newChatTitle; |
||
186 | |||
187 | /** |
||
188 | * Optional. A group photo was change to this value |
||
189 | * |
||
190 | * @var mixed |
||
191 | */ |
||
192 | protected $newChatPhoto; |
||
193 | |||
194 | /** |
||
195 | * Optional. Informs that the group photo was deleted |
||
196 | * |
||
197 | * @var bool |
||
198 | */ |
||
199 | protected $deleteChatPhoto; |
||
200 | |||
201 | /** |
||
202 | * Optional. Informs that the group has been created |
||
203 | * |
||
204 | * @var bool |
||
205 | */ |
||
206 | protected $groupChatCreated; |
||
207 | |||
208 | /** |
||
209 | * Optional. Text description of the video (usually empty) |
||
210 | * |
||
211 | * @var string |
||
212 | */ |
||
213 | protected $caption; |
||
214 | |||
215 | |||
216 | /** |
||
217 | * Optional. Service message: the supergroup has been created |
||
218 | * |
||
219 | * @var bool |
||
220 | */ |
||
221 | protected $supergroupChatCreated; |
||
222 | |||
223 | /** |
||
224 | * Optional. Service message: the channel has been created |
||
225 | * |
||
226 | * @var bool |
||
227 | */ |
||
228 | protected $channelChatCreated; |
||
229 | |||
230 | /** |
||
231 | * Optional. The group has been migrated to a supergroup with the specified identifier, |
||
232 | * not exceeding 1e13 by absolute value |
||
233 | * |
||
234 | * @var int |
||
235 | */ |
||
236 | protected $migrateToChatId; |
||
237 | |||
238 | /** |
||
239 | * Optional. The supergroup has been migrated from a group with the specified identifier, |
||
240 | * not exceeding 1e13 by absolute value |
||
241 | * |
||
242 | * @var int |
||
243 | */ |
||
244 | protected $migrateFromChatId; |
||
245 | |||
246 | /** |
||
247 | * @return string |
||
248 | */ |
||
249 | 3 | public function getCaption() |
|
253 | |||
254 | /** |
||
255 | * @param string $caption |
||
256 | */ |
||
257 | 6 | public function setCaption($caption) |
|
261 | |||
262 | /** |
||
263 | * @return Audio |
||
264 | */ |
||
265 | 3 | public function getAudio() |
|
269 | |||
270 | /** |
||
271 | * @param Audio $audio |
||
272 | */ |
||
273 | 6 | public function setAudio(Audio $audio) |
|
277 | |||
278 | /** |
||
279 | * @return TypeInterface |
||
280 | */ |
||
281 | 6 | public function getChat() |
|
285 | |||
286 | /** |
||
287 | * @param Chat $chat |
||
288 | */ |
||
289 | 18 | public function setChat(Chat $chat) |
|
293 | |||
294 | /** |
||
295 | * @return Contact |
||
296 | */ |
||
297 | 3 | public function getContact() |
|
301 | |||
302 | /** |
||
303 | * @param Contact $contact |
||
304 | */ |
||
305 | 6 | public function setContact(Contact $contact) |
|
309 | |||
310 | /** |
||
311 | * @return int |
||
312 | */ |
||
313 | 3 | public function getDate() |
|
317 | |||
318 | /** |
||
319 | * @param int $date |
||
320 | * |
||
321 | * @throws InvalidArgumentException |
||
322 | */ |
||
323 | 15 | public function setDate($date) |
|
331 | |||
332 | /** |
||
333 | * @return boolean |
||
334 | */ |
||
335 | 3 | public function isDeleteChatPhoto() |
|
339 | |||
340 | /** |
||
341 | * @param boolean $deleteChatPhoto |
||
342 | */ |
||
343 | 6 | public function setDeleteChatPhoto($deleteChatPhoto) |
|
347 | |||
348 | /** |
||
349 | * @return Document |
||
350 | */ |
||
351 | 3 | public function getDocument() |
|
355 | |||
356 | /** |
||
357 | * @param Document $document |
||
358 | */ |
||
359 | 6 | public function setDocument($document) |
|
363 | |||
364 | /** |
||
365 | * @return int |
||
366 | */ |
||
367 | 3 | public function getForwardDate() |
|
371 | |||
372 | /** |
||
373 | * @param int $forwardDate |
||
374 | * |
||
375 | * @throws InvalidArgumentException |
||
376 | */ |
||
377 | 9 | public function setForwardDate($forwardDate) |
|
385 | |||
386 | /** |
||
387 | * @return User |
||
388 | */ |
||
389 | 3 | public function getForwardFrom() |
|
393 | |||
394 | /** |
||
395 | * @param User $forwardFrom |
||
396 | */ |
||
397 | 6 | public function setForwardFrom(User $forwardFrom) |
|
401 | |||
402 | /** |
||
403 | * @return boolean |
||
404 | */ |
||
405 | 3 | public function isGroupChatCreated() |
|
409 | |||
410 | /** |
||
411 | * @param boolean $groupChatCreated |
||
412 | */ |
||
413 | 6 | public function setGroupChatCreated($groupChatCreated) |
|
417 | |||
418 | /** |
||
419 | * @return User |
||
420 | */ |
||
421 | 3 | public function getLeftChatParticipant() |
|
425 | |||
426 | /** |
||
427 | * @param User $leftChatParticipant |
||
428 | */ |
||
429 | 6 | public function setLeftChatParticipant($leftChatParticipant) |
|
433 | |||
434 | /** |
||
435 | * @return Location |
||
436 | */ |
||
437 | 3 | public function getLocation() |
|
441 | |||
442 | /** |
||
443 | * @param Location $location |
||
444 | */ |
||
445 | 6 | public function setLocation(Location $location) |
|
449 | |||
450 | /** |
||
451 | * @return int |
||
452 | */ |
||
453 | 3 | public function getMessageId() |
|
457 | |||
458 | /** |
||
459 | * @param int $messageId |
||
460 | * |
||
461 | * @throws InvalidArgumentException |
||
462 | */ |
||
463 | 15 | public function setMessageId($messageId) |
|
471 | |||
472 | /** |
||
473 | * @return User |
||
474 | */ |
||
475 | 3 | public function getNewChatParticipant() |
|
479 | |||
480 | /** |
||
481 | * @param User $newChatParticipant |
||
482 | */ |
||
483 | 6 | public function setNewChatParticipant($newChatParticipant) |
|
487 | |||
488 | /** |
||
489 | * @return array |
||
490 | */ |
||
491 | 3 | public function getNewChatPhoto() |
|
495 | |||
496 | /** |
||
497 | * @param array $newChatPhoto |
||
498 | */ |
||
499 | 6 | public function setNewChatPhoto($newChatPhoto) |
|
503 | |||
504 | /** |
||
505 | * @return string |
||
506 | */ |
||
507 | 3 | public function getNewChatTitle() |
|
511 | |||
512 | /** |
||
513 | * @param string $newChatTitle |
||
514 | */ |
||
515 | 6 | public function setNewChatTitle($newChatTitle) |
|
519 | |||
520 | /** |
||
521 | * @return array |
||
522 | */ |
||
523 | 3 | public function getPhoto() |
|
527 | |||
528 | /** |
||
529 | * @param array $photo |
||
530 | */ |
||
531 | 6 | public function setPhoto(array $photo) |
|
535 | |||
536 | /** |
||
537 | * @return Message |
||
538 | */ |
||
539 | 3 | public function getReplyToMessage() |
|
543 | |||
544 | /** |
||
545 | * @param Message $replyToMessage |
||
546 | */ |
||
547 | 6 | public function setReplyToMessage(Message $replyToMessage) |
|
551 | |||
552 | /** |
||
553 | * @return Sticker |
||
554 | */ |
||
555 | 3 | public function getSticker() |
|
559 | |||
560 | /** |
||
561 | * @param Sticker $sticker |
||
562 | */ |
||
563 | 6 | public function setSticker(Sticker $sticker) |
|
567 | |||
568 | /** |
||
569 | * @return string |
||
570 | */ |
||
571 | 3 | public function getText() |
|
575 | |||
576 | /** |
||
577 | * @param string $text |
||
578 | */ |
||
579 | 6 | public function setText($text) |
|
583 | |||
584 | /** |
||
585 | * @return User |
||
586 | */ |
||
587 | 3 | public function getFrom() |
|
591 | |||
592 | /** |
||
593 | * @param User $from |
||
594 | */ |
||
595 | 12 | public function setFrom(User $from) |
|
599 | |||
600 | /** |
||
601 | * @return Video |
||
602 | */ |
||
603 | 3 | public function getVideo() |
|
607 | |||
608 | /** |
||
609 | * @param Video $video |
||
610 | */ |
||
611 | 6 | public function setVideo(Video $video) |
|
615 | |||
616 | /** |
||
617 | * @return Voice |
||
618 | */ |
||
619 | 3 | public function getVoice() |
|
623 | |||
624 | /** |
||
625 | * @param Voice $voice |
||
626 | */ |
||
627 | 6 | public function setVoice($voice) |
|
631 | |||
632 | /** |
||
633 | * @param boolean $supergroupChatCreated |
||
634 | */ |
||
635 | public function setSupergroupChatCreated($supergroupChatCreated) |
||
639 | |||
640 | /** |
||
641 | * @return boolean |
||
642 | */ |
||
643 | public function isSupergroupChatCreated() |
||
647 | |||
648 | /** |
||
649 | * @param boolean $channelChatCreated |
||
650 | */ |
||
651 | public function setChannelChatCreated($channelChatCreated) |
||
655 | |||
656 | /** |
||
657 | * @return boolean |
||
658 | */ |
||
659 | public function isChannelChatCreated() |
||
663 | |||
664 | /** |
||
665 | * @param int $migrateToChatId |
||
666 | */ |
||
667 | public function setMigrateToChatId($migrateToChatId) |
||
671 | |||
672 | /** |
||
673 | * @return int |
||
674 | */ |
||
675 | public function getMigrateToChatId() |
||
679 | |||
680 | /** |
||
681 | * @param int $migrateFromChatId |
||
682 | */ |
||
683 | public function setMigrateFromChatId($migrateFromChatId) |
||
687 | |||
688 | /** |
||
689 | * @return int |
||
690 | */ |
||
691 | public function getMigrateFromChatId() |
||
695 | } |
||
696 |