Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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 |
||
15 | class Message extends Entity |
||
16 | { |
||
17 | /** |
||
18 | * @var mixed|null |
||
19 | */ |
||
20 | protected $message_id; |
||
21 | |||
22 | /** |
||
23 | * @var \Longman\TelegramBot\Entities\User|null |
||
24 | */ |
||
25 | protected $from; |
||
26 | |||
27 | /** |
||
28 | * @var mixed|null |
||
29 | */ |
||
30 | protected $date; |
||
31 | |||
32 | /** |
||
33 | * @var \Longman\TelegramBot\Entities\Chat|null |
||
34 | */ |
||
35 | protected $chat; |
||
36 | |||
37 | /** |
||
38 | * @var \Longman\TelegramBot\Entities\User|null |
||
39 | */ |
||
40 | protected $forward_from; |
||
41 | |||
42 | /** |
||
43 | * @var \Longman\TelegramBot\Entities\Chat|null |
||
44 | */ |
||
45 | protected $forward_from_chat; |
||
46 | |||
47 | /** |
||
48 | * @var mixed|null |
||
49 | */ |
||
50 | protected $forward_date; |
||
51 | |||
52 | /** |
||
53 | * @var mixed|null |
||
54 | */ |
||
55 | protected $edit_date; |
||
56 | |||
57 | /** |
||
58 | * @var \Longman\TelegramBot\Entities\ReplyToMessage |
||
59 | */ |
||
60 | protected $reply_to_message; |
||
61 | |||
62 | /** |
||
63 | * @var string|null |
||
64 | */ |
||
65 | protected $text; |
||
66 | |||
67 | /** |
||
68 | * @var \Longman\TelegramBot\Entities\Audio|null |
||
69 | */ |
||
70 | protected $audio; |
||
71 | |||
72 | /** |
||
73 | * @var \Longman\TelegramBot\Entities\Document|null |
||
74 | */ |
||
75 | protected $document; |
||
76 | |||
77 | /** |
||
78 | * @var array|null |
||
79 | */ |
||
80 | protected $photo; |
||
81 | |||
82 | /** |
||
83 | * @var \Longman\TelegramBot\Entities\Sticker|null |
||
84 | */ |
||
85 | protected $sticker; |
||
86 | |||
87 | /** |
||
88 | * @var \Longman\TelegramBot\Entities\Video|null |
||
89 | */ |
||
90 | protected $video; |
||
91 | |||
92 | /** |
||
93 | * @var \Longman\TelegramBot\Entities\Voice|null |
||
94 | */ |
||
95 | protected $voice; |
||
96 | |||
97 | /** |
||
98 | * @var mixed|null |
||
99 | */ |
||
100 | protected $caption; |
||
101 | |||
102 | /** |
||
103 | * @var \Longman\TelegramBot\Entities\Contact|null |
||
104 | */ |
||
105 | protected $contact; |
||
106 | |||
107 | /** |
||
108 | * @var \Longman\TelegramBot\Entities\Location|null |
||
109 | */ |
||
110 | protected $location; |
||
111 | |||
112 | /** |
||
113 | * @var mixed|null |
||
114 | */ |
||
115 | protected $venue; |
||
116 | |||
117 | /** |
||
118 | * @var \Longman\TelegramBot\Entities\User|null |
||
119 | */ |
||
120 | protected $new_chat_member; |
||
121 | |||
122 | /** |
||
123 | * @var \Longman\TelegramBot\Entities\User|null |
||
124 | */ |
||
125 | protected $left_chat_member; |
||
126 | |||
127 | /** |
||
128 | * @var mixed|null |
||
129 | */ |
||
130 | protected $new_chat_title; |
||
131 | |||
132 | /** |
||
133 | * @var mixed|null |
||
134 | */ |
||
135 | protected $new_chat_photo; |
||
136 | |||
137 | /** |
||
138 | * @var mixed|null |
||
139 | */ |
||
140 | protected $delete_chat_photo; |
||
141 | |||
142 | /** |
||
143 | * @var mixed|null |
||
144 | */ |
||
145 | protected $group_chat_created; |
||
146 | |||
147 | /** |
||
148 | * @var mixed|null |
||
149 | */ |
||
150 | protected $supergroup_chat_created; |
||
151 | |||
152 | /** |
||
153 | * @var mixed|null |
||
154 | */ |
||
155 | protected $channel_chat_created; |
||
156 | |||
157 | /** |
||
158 | * @var mixed|null |
||
159 | */ |
||
160 | protected $migrate_to_chat_id; |
||
161 | |||
162 | /** |
||
163 | * @var mixed|null |
||
164 | */ |
||
165 | protected $migrate_from_chat_id; |
||
166 | |||
167 | /** |
||
168 | * @var mixed|null |
||
169 | */ |
||
170 | protected $pinned_message; |
||
171 | |||
172 | /** |
||
173 | * @var mixed|null |
||
174 | */ |
||
175 | protected $entities; |
||
176 | |||
177 | /** |
||
178 | * @var mixed|null |
||
179 | */ |
||
180 | private $command; |
||
181 | |||
182 | /** |
||
183 | * @var mixed|null |
||
184 | */ |
||
185 | private $type; |
||
186 | |||
187 | /** |
||
188 | * Message constructor. |
||
189 | * |
||
190 | * @param array $data |
||
191 | * @param $bot_name |
||
192 | */ |
||
193 | 18 | public function __construct(array $data, $bot_name) |
|
194 | { |
||
195 | |||
196 | 18 | $this->reply_to_message = isset($data['reply_to_message']) ? $data['reply_to_message'] : null; |
|
197 | 18 | if (!empty($this->reply_to_message)) { |
|
198 | 2 | $this->reply_to_message = new ReplyToMessage($this->reply_to_message, $bot_name); |
|
199 | } |
||
200 | |||
201 | 18 | $this->init($data, $bot_name); |
|
202 | 18 | } |
|
203 | |||
204 | /** |
||
205 | * Common init to Message and ReplyToMessage |
||
206 | * |
||
207 | * @param array $data |
||
208 | * @param string $bot_name |
||
209 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
210 | */ |
||
211 | 18 | protected function init(array &$data, $bot_name) |
|
212 | { |
||
213 | 18 | $this->bot_name = $bot_name; |
|
214 | |||
215 | 18 | $this->type = 'Message'; |
|
216 | |||
217 | 18 | $this->message_id = isset($data['message_id']) ? $data['message_id'] : null; |
|
218 | 18 | if (empty($this->message_id)) { |
|
219 | throw new TelegramException('message_id is empty!'); |
||
220 | } |
||
221 | |||
222 | 18 | $this->from = isset($data['from']) ? $data['from'] : null; |
|
223 | 18 | if (!empty($this->from)) { |
|
224 | 17 | $this->from = new User($this->from); |
|
225 | } |
||
226 | |||
227 | 18 | $this->chat = isset($data['chat']) ? $data['chat'] : null; |
|
228 | 18 | if (empty($this->chat)) { |
|
229 | throw new TelegramException('chat is empty!'); |
||
230 | } |
||
231 | 18 | $this->chat = new Chat($this->chat); |
|
232 | |||
233 | 18 | $this->date = isset($data['date']) ? $data['date'] : null; |
|
234 | 18 | if (empty($this->date)) { |
|
235 | throw new TelegramException('date is empty!'); |
||
236 | } |
||
237 | |||
238 | 18 | $this->forward_from = isset($data['forward_from']) ? $data['forward_from'] : null; |
|
239 | 18 | if (!empty($this->forward_from)) { |
|
240 | $this->forward_from = new User($this->forward_from); |
||
241 | } |
||
242 | |||
243 | 18 | $this->forward_from_chat = isset($data['forward_from_chat']) ? $data['forward_from_chat'] : null; |
|
244 | 18 | if (!empty($this->forward_from_chat)) { |
|
245 | $this->forward_from_chat = new Chat($this->forward_from_chat); |
||
246 | } |
||
247 | |||
248 | 18 | $this->forward_date = isset($data['forward_date']) ? $data['forward_date'] : null; |
|
249 | |||
250 | 18 | $this->edit_date = isset($data['edit_date']) ? $data['edit_date'] : null; |
|
251 | |||
252 | 18 | $this->text = isset($data['text']) ? $data['text'] : null; |
|
253 | 18 | $command = $this->getCommand(); |
|
254 | 18 | if (!empty($command)) { |
|
255 | 7 | $this->type = 'command'; |
|
256 | } |
||
257 | |||
258 | 18 | $this->audio = isset($data['audio']) ? $data['audio'] : null; |
|
259 | 18 | if (!empty($this->audio)) { |
|
260 | $this->audio = new Audio($this->audio); |
||
261 | $this->type = 'Audio'; |
||
262 | } |
||
263 | |||
264 | 18 | $this->document = isset($data['document']) ? $data['document'] : null; |
|
265 | 18 | if (!empty($this->document)) { |
|
266 | $this->document = new Document($this->document); |
||
267 | $this->type = 'Document'; |
||
268 | } |
||
269 | |||
270 | 18 | $this->photo = isset($data['photo']) ? $data['photo'] : null; //array of photosize |
|
271 | 18 | View Code Duplication | if (!empty($this->photo)) { |
|
|||
272 | foreach ($this->photo as $photo) { |
||
273 | if (!empty($photo)) { |
||
274 | $photos[] = new PhotoSize($photo); |
||
275 | } |
||
276 | } |
||
277 | $this->photo = $photos; |
||
278 | $this->type = 'Photo'; |
||
279 | } |
||
280 | |||
281 | 18 | $this->sticker = isset($data['sticker']) ? $data['sticker'] : null; |
|
282 | 18 | if (!empty($this->sticker)) { |
|
283 | $this->sticker = new Sticker($this->sticker); |
||
284 | $this->type = 'Sticker'; |
||
285 | } |
||
286 | |||
287 | 18 | $this->video = isset($data['video']) ? $data['video'] : null; |
|
288 | 18 | if (!empty($this->video)) { |
|
289 | $this->video = new Video($this->video); |
||
290 | $this->type = 'Video'; |
||
291 | } |
||
292 | |||
293 | 18 | $this->voice = isset($data['voice']) ? $data['voice'] : null; |
|
294 | 18 | if (!empty($this->voice)) { |
|
295 | $this->voice = new Voice($this->voice); |
||
296 | $this->type = 'Voice'; |
||
297 | } |
||
298 | |||
299 | 18 | $this->caption = isset($data['caption']) ? $data['caption'] : null;//string |
|
300 | |||
301 | 18 | $this->contact = isset($data['contact']) ? $data['contact'] : null; |
|
302 | 18 | if (!empty($this->contact)) { |
|
303 | $this->contact = new Contact($this->contact); |
||
304 | } |
||
305 | |||
306 | 18 | $this->location = isset($data['location']) ? $data['location'] : null; |
|
307 | 18 | if (!empty($this->location)) { |
|
308 | $this->location = new Location($this->location); |
||
309 | $this->type = 'Location'; |
||
310 | } |
||
311 | |||
312 | 18 | $this->venue = isset($data['venue']) ? $data['venue'] : null; |
|
313 | 18 | if (!empty($this->venue)) { |
|
314 | $this->venue = new Venue($this->venue); |
||
315 | $this->type = 'Venue'; |
||
316 | } |
||
317 | |||
318 | //retrocompatibility |
||
319 | 18 | if (isset($data['new_chat_participant'])) { |
|
320 | $data['new_chat_member'] = $data['new_chat_participant']; |
||
321 | } |
||
322 | |||
323 | 18 | if (isset($data['left_chat_participant'])) { |
|
324 | $data['left_chat_member'] = $data['left_chat_participant']; |
||
325 | } |
||
326 | |||
327 | 18 | $this->new_chat_member = isset($data['new_chat_member']) ? $data['new_chat_member'] : null; |
|
328 | 18 | if (!empty($this->new_chat_member)) { |
|
329 | $this->new_chat_member = new User($this->new_chat_member); |
||
330 | $this->type = 'new_chat_member'; |
||
331 | } |
||
332 | |||
333 | 18 | $this->left_chat_member = isset($data['left_chat_member']) ? $data['left_chat_member'] : null; |
|
334 | 18 | if (!empty($this->left_chat_member)) { |
|
335 | $this->left_chat_member = new User($this->left_chat_member); |
||
336 | $this->type = 'left_chat_member'; |
||
337 | } |
||
338 | |||
339 | 18 | $this->new_chat_title = isset($data['new_chat_title']) ? $data['new_chat_title'] : null; |
|
340 | 18 | if (!is_null($this->new_chat_title)) { |
|
341 | $this->type = 'new_chat_title'; |
||
342 | } |
||
343 | |||
344 | 18 | $this->new_chat_photo = isset($data['new_chat_photo']) ? $data['new_chat_photo'] : null; //array of photosize |
|
345 | 18 | View Code Duplication | if (!empty($this->new_chat_photo)) { |
346 | foreach ($this->new_chat_photo as $photo) { |
||
347 | if (!empty($photo)) { |
||
348 | $photos[] = new PhotoSize($photo); |
||
349 | } |
||
350 | } |
||
351 | $this->new_chat_photo = $photos; |
||
352 | $this->type = 'new_chat_photo'; |
||
353 | } |
||
354 | |||
355 | 18 | $this->delete_chat_photo = isset($data['delete_chat_photo']) ? $data['delete_chat_photo'] : null; |
|
356 | 18 | if ($this->delete_chat_photo) { |
|
357 | $this->type = 'delete_chat_photo'; |
||
358 | } |
||
359 | |||
360 | 18 | $this->group_chat_created = isset($data['group_chat_created']) ? $data['group_chat_created'] : null; |
|
361 | 18 | if ($this->group_chat_created) { |
|
362 | $this->type = 'group_chat_created'; |
||
363 | } |
||
364 | |||
365 | 18 | $this->supergroup_chat_created = isset($data['supergroup_chat_created']) ? $data['supergroup_chat_created'] : null; |
|
366 | 18 | if ($this->supergroup_chat_created) { |
|
367 | $this->type = 'supergroup_chat_created'; |
||
368 | } |
||
369 | |||
370 | 18 | $this->channel_chat_created = isset($data['channel_chat_created']) ? $data['channel_chat_created'] : null; |
|
371 | 18 | if ($this->channel_chat_created) { |
|
372 | $this->type = 'channel_chat_created'; |
||
373 | } |
||
374 | |||
375 | 18 | $this->migrate_to_chat_id = isset($data['migrate_to_chat_id']) ? $data['migrate_to_chat_id'] : null; |
|
376 | 18 | if ($this->migrate_to_chat_id) { |
|
377 | $this->type = 'migrate_to_chat_id'; |
||
378 | } |
||
379 | |||
380 | 18 | $this->migrate_from_chat_id = isset($data['migrate_from_chat_id']) ? $data['migrate_from_chat_id'] : null; |
|
381 | 18 | if ($this->migrate_from_chat_id) { |
|
382 | $this->type = 'migrate_from_chat_id'; |
||
383 | } |
||
384 | |||
385 | 18 | $this->pinned_message = isset($data['pinned_message']) ? $data['pinned_message'] : null; |
|
386 | 18 | if ($this->pinned_message) { |
|
387 | $this->pinned_message = new Message($this->pinned_message, $this->getBotName()); |
||
388 | } |
||
389 | |||
390 | 18 | $this->entities = isset($data['entities']) ? $data['entities'] : null; |
|
391 | 18 | if (!empty($this->entities)) { |
|
392 | foreach ($this->entities as $entity) { |
||
393 | if (!empty($entity)) { |
||
394 | $entities[] = new MessageEntity($entity); |
||
395 | } |
||
396 | } |
||
397 | $this->entities = $entities; |
||
398 | } |
||
399 | 18 | } |
|
400 | |||
401 | /** |
||
402 | * return the entire command like /echo or /echo@bot1 if specified |
||
403 | * |
||
404 | * @return string|void |
||
405 | */ |
||
406 | 18 | public function getFullCommand() |
|
422 | |||
423 | /** |
||
424 | * Get command |
||
425 | * |
||
426 | * @return bool|string |
||
427 | */ |
||
428 | 18 | public function getCommand() |
|
429 | { |
||
430 | 18 | if (!empty($this->command)) { |
|
431 | 1 | return $this->command; |
|
432 | } |
||
433 | |||
434 | 18 | $cmd = $this->getFullCommand(); |
|
435 | |||
436 | 18 | if (substr($cmd, 0, 1) === '/') { |
|
437 | 7 | $cmd = substr($cmd, 1); |
|
438 | |||
439 | //check if command is follow by botname |
||
440 | 7 | $split_cmd = explode('@', $cmd); |
|
441 | 7 | if (isset($split_cmd[1])) { |
|
442 | //command is followed by name check if is addressed to me |
||
443 | 1 | if (strtolower($split_cmd[1]) == strtolower($this->bot_name)) { |
|
444 | 1 | return $this->command = $split_cmd[0]; |
|
445 | } |
||
446 | } else { |
||
447 | //command is not followed by name |
||
448 | 7 | return $this->command = $cmd; |
|
449 | } |
||
450 | } |
||
451 | |||
452 | 18 | return false; |
|
453 | } |
||
454 | |||
455 | /** |
||
456 | * Get message id |
||
457 | * |
||
458 | * @return mixed |
||
459 | */ |
||
460 | 11 | public function getMessageId() |
|
464 | |||
465 | /** |
||
466 | * Get User object related to the message |
||
467 | * |
||
468 | * @return \Longman\TelegramBot\Entities\User |
||
469 | */ |
||
470 | 8 | public function getFrom() |
|
471 | { |
||
472 | 8 | return $this->from; |
|
473 | } |
||
474 | |||
475 | /** |
||
476 | * Get date |
||
477 | * |
||
478 | * @return mixed |
||
479 | */ |
||
480 | 8 | public function getDate() |
|
484 | |||
485 | /** |
||
486 | * Get User object related to the message |
||
487 | * |
||
488 | * @return \Longman\TelegramBot\Entities\Chat |
||
489 | */ |
||
490 | 13 | public function getChat() |
|
491 | { |
||
492 | 13 | return $this->chat; |
|
493 | } |
||
494 | |||
495 | /** |
||
496 | * Get User object related to the forwarded message |
||
497 | * |
||
498 | * @return \Longman\TelegramBot\Entities\User |
||
499 | */ |
||
500 | 6 | public function getForwardFrom() |
|
501 | { |
||
502 | 6 | return $this->forward_from; |
|
503 | } |
||
504 | |||
505 | /** |
||
506 | * Get User object related to the message |
||
507 | * |
||
508 | * @return \Longman\TelegramBot\Entities\Chat |
||
509 | */ |
||
510 | 6 | public function getForwardFromChat() |
|
511 | { |
||
512 | 6 | return $this->forward_from_chat; |
|
513 | } |
||
514 | |||
515 | /** |
||
516 | * Get forward date |
||
517 | * |
||
518 | * @return mixed |
||
519 | */ |
||
520 | public function getForwardDate() |
||
521 | { |
||
522 | return $this->forward_date; |
||
523 | } |
||
524 | |||
525 | /** |
||
526 | * Get edit date |
||
527 | * |
||
528 | * @return mixed |
||
529 | */ |
||
530 | public function getEditDate() |
||
531 | { |
||
532 | return $this->edit_date; |
||
533 | } |
||
534 | |||
535 | /** |
||
536 | * Get reply to message |
||
537 | * |
||
538 | * @return \Longman\TelegramBot\Entities\ReplyToMessage |
||
539 | */ |
||
540 | 7 | public function getReplyToMessage() |
|
544 | |||
545 | /** |
||
546 | * Get text |
||
547 | * |
||
548 | * @param bool $without_cmd |
||
549 | * @return string |
||
550 | */ |
||
551 | 14 | public function getText($without_cmd = false) |
|
552 | { |
||
553 | 14 | $text = $this->text; |
|
554 | |||
555 | 14 | if ($without_cmd && $command = $this->getFullCommand()) { |
|
556 | 6 | if (strlen($command) + 1 < strlen($text)) { |
|
557 | 5 | $text = substr($text, strlen($command) + 1); |
|
558 | } else { |
||
559 | 3 | $text = ''; |
|
560 | } |
||
561 | } |
||
562 | |||
563 | 14 | return $text; |
|
564 | } |
||
565 | |||
566 | /** |
||
567 | * Get audio |
||
568 | * |
||
569 | * @return \Longman\TelegramBot\Entities\Audio |
||
570 | */ |
||
571 | 6 | public function getAudio() |
|
572 | { |
||
573 | 6 | return $this->audio; |
|
574 | } |
||
575 | |||
576 | /** |
||
577 | * Get document |
||
578 | * |
||
579 | * @return \Longman\TelegramBot\Entities\Document |
||
580 | */ |
||
581 | 6 | public function getDocument() |
|
585 | |||
586 | /** |
||
587 | * Get photo |
||
588 | * |
||
589 | * @return array |
||
590 | */ |
||
591 | 6 | public function getPhoto() |
|
592 | { |
||
593 | 6 | return $this->photo; |
|
594 | } |
||
595 | |||
596 | /** |
||
597 | * Get sticker |
||
598 | * |
||
599 | * @return \Longman\TelegramBot\Entities\Sticker |
||
600 | */ |
||
601 | 6 | public function getSticker() |
|
602 | { |
||
603 | 6 | return $this->sticker; |
|
604 | } |
||
605 | |||
606 | /** |
||
607 | * Get video |
||
608 | * |
||
609 | * @return \Longman\TelegramBot\Entities\Video |
||
610 | */ |
||
611 | 6 | public function getVideo() |
|
612 | { |
||
613 | 6 | return $this->video; |
|
614 | } |
||
615 | |||
616 | /** |
||
617 | * Get voice |
||
618 | * |
||
619 | * @return \Longman\TelegramBot\Entities\Voice |
||
620 | */ |
||
621 | 6 | public function getVoice() |
|
622 | { |
||
623 | 6 | return $this->voice; |
|
624 | } |
||
625 | |||
626 | /** |
||
627 | * Get caption |
||
628 | * |
||
629 | * @return mixed |
||
630 | */ |
||
631 | 6 | public function getCaption() |
|
632 | { |
||
633 | 6 | return $this->caption; |
|
634 | } |
||
635 | |||
636 | /** |
||
637 | * Get content |
||
638 | * |
||
639 | * @return \Longman\TelegramBot\Entities\Contact |
||
640 | */ |
||
641 | 6 | public function getContact() |
|
642 | { |
||
643 | 6 | return $this->contact; |
|
644 | } |
||
645 | |||
646 | /** |
||
647 | * Get location |
||
648 | * |
||
649 | * @return \Longman\TelegramBot\Entities\Location |
||
650 | */ |
||
651 | 6 | public function getLocation() |
|
652 | { |
||
653 | 6 | return $this->location; |
|
654 | } |
||
655 | |||
656 | /** |
||
657 | * Get venue |
||
658 | * |
||
659 | * @return mixed |
||
660 | */ |
||
661 | 6 | public function getVenue() |
|
662 | { |
||
663 | 6 | return $this->venue; |
|
664 | } |
||
665 | |||
666 | /** |
||
667 | * Get new chat participant |
||
668 | * |
||
669 | * @return mixed |
||
670 | */ |
||
671 | public function getNewChatParticipant() |
||
675 | |||
676 | /** |
||
677 | * Get left chat participant |
||
678 | * |
||
679 | * @return mixed |
||
680 | */ |
||
681 | public function getLeftChatParticipant() |
||
685 | |||
686 | /** |
||
687 | * Get User object related to the new member |
||
688 | * |
||
689 | * @return \Longman\TelegramBot\Entities\User |
||
690 | */ |
||
691 | 6 | public function getNewChatMember() |
|
692 | { |
||
693 | 6 | return $this->new_chat_member; |
|
694 | } |
||
695 | |||
696 | /** |
||
697 | * Get User object related to the left member |
||
698 | * |
||
699 | * @return \Longman\TelegramBot\Entities\User |
||
700 | */ |
||
701 | 6 | public function getLeftChatMember() |
|
702 | { |
||
703 | 6 | return $this->left_chat_member; |
|
704 | } |
||
705 | |||
706 | /** |
||
707 | * Get new chat title |
||
708 | * |
||
709 | * @return mixed |
||
710 | */ |
||
711 | 6 | public function getNewChatTitle() |
|
712 | { |
||
713 | 6 | return $this->new_chat_title; |
|
714 | } |
||
715 | |||
716 | /** |
||
717 | * Get new chat photo |
||
718 | * |
||
719 | * @return mixed |
||
720 | */ |
||
721 | 6 | public function getNewChatPhoto() |
|
722 | { |
||
723 | 6 | return $this->new_chat_photo; |
|
724 | } |
||
725 | |||
726 | /** |
||
727 | * Get delete chat photo |
||
728 | * |
||
729 | * @return mixed |
||
730 | */ |
||
731 | 6 | public function getDeleteChatPhoto() |
|
732 | { |
||
733 | 6 | return $this->delete_chat_photo; |
|
734 | } |
||
735 | |||
736 | /** |
||
737 | * Get group chat created |
||
738 | * |
||
739 | * @return mixed |
||
740 | */ |
||
741 | 6 | public function getGroupChatCreated() |
|
742 | { |
||
743 | 6 | return $this->group_chat_created; |
|
744 | } |
||
745 | |||
746 | /** |
||
747 | * Get supergroup chat created |
||
748 | * |
||
749 | * @return mixed |
||
750 | */ |
||
751 | 6 | public function getSupergroupChatCreated() |
|
752 | { |
||
753 | 6 | return $this->supergroup_chat_created; |
|
754 | } |
||
755 | |||
756 | /** |
||
757 | * Get channel chat created |
||
758 | * |
||
759 | * @return mixed |
||
760 | */ |
||
761 | 6 | public function getChannelChatCreated() |
|
762 | { |
||
763 | 6 | return $this->channel_chat_created; |
|
764 | } |
||
765 | |||
766 | /** |
||
767 | * Get migrate to chat id |
||
768 | * |
||
769 | * @return mixed |
||
770 | */ |
||
771 | 6 | public function getMigrateToChatId() |
|
772 | { |
||
773 | 6 | return $this->migrate_to_chat_id; |
|
774 | } |
||
775 | |||
776 | /** |
||
777 | * Get migrate from chat id |
||
778 | * |
||
779 | * @return mixed |
||
780 | */ |
||
781 | 6 | public function getMigrateFromChatId() |
|
782 | { |
||
783 | 6 | return $this->migrate_from_chat_id; |
|
784 | } |
||
785 | |||
786 | /** |
||
787 | * Bot added in chat |
||
788 | * |
||
789 | * @return bool |
||
790 | */ |
||
791 | public function botAddedInChat() |
||
792 | { |
||
793 | if (!empty($this->new_chat_member)) { |
||
794 | if ($this->new_chat_member->getUsername() == $this->getBotName()) { |
||
795 | return true; |
||
796 | } |
||
797 | } |
||
798 | |||
799 | return false; |
||
800 | } |
||
801 | |||
802 | /** |
||
803 | * Get type |
||
804 | * |
||
805 | * @return mixed |
||
806 | */ |
||
807 | public function getType() |
||
811 | |||
812 | /** |
||
813 | * Get pinned message |
||
814 | * |
||
815 | * @return mixed |
||
816 | */ |
||
817 | 6 | public function getPinnedMessage() |
|
818 | { |
||
819 | 6 | return $this->pinned_message; |
|
820 | } |
||
821 | |||
822 | /** |
||
823 | * Get entities |
||
824 | * |
||
825 | * @return mixed |
||
826 | */ |
||
827 | 6 | public function getEntities() |
|
828 | { |
||
829 | 6 | return $this->entities; |
|
830 | } |
||
831 | } |
||
832 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.