Completed
Push — master ( 1f7e67...a1b9db )
by
unknown
07:31
created

Message   C

Complexity

Total Complexity 68

Size/Duplication

Total Lines 814
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Test Coverage

Coverage 86.98%

Importance

Changes 0
Metric Value
wmc 68
lcom 3
cbo 2
dl 0
loc 814
ccs 147
cts 169
cp 0.8698
rs 5
c 0
b 0
f 0

64 Methods

Rating   Name   Duplication   Size   Complexity  
A getCaption() 0 4 1
A setCaption() 0 4 1
A getAudio() 0 4 1
A setAudio() 0 4 1
A getChat() 0 4 1
A setChat() 0 4 1
A getContact() 0 4 1
A setContact() 0 4 1
A getDate() 0 4 1
A setDate() 0 8 2
A isDeleteChatPhoto() 0 4 1
A setDeleteChatPhoto() 0 4 1
A getDocument() 0 4 1
A setDocument() 0 4 1
A getForwardDate() 0 4 1
A setForwardDate() 0 8 2
A getForwardFrom() 0 4 1
A setForwardFrom() 0 4 1
A isGroupChatCreated() 0 4 1
A setGroupChatCreated() 0 4 1
A getLeftChatMember() 0 4 1
A setLeftChatMember() 0 4 1
A getLocation() 0 4 1
A setLocation() 0 4 1
A getVenue() 0 4 1
A setVenue() 0 4 1
A getMessageId() 0 4 1
A setMessageId() 0 8 3
A getNewChatMember() 0 4 1
A setNewChatMember() 0 4 1
A getNewChatPhoto() 0 4 1
A setNewChatPhoto() 0 4 1
A getNewChatTitle() 0 4 1
A setNewChatTitle() 0 4 1
A getPhoto() 0 4 1
A setPhoto() 0 4 1
A getReplyToMessage() 0 4 1
A setReplyToMessage() 0 4 1
A getSticker() 0 4 1
A setSticker() 0 4 1
A getText() 0 4 1
A setText() 0 4 1
A getEntities() 0 4 1
A setEntities() 0 4 1
A getFrom() 0 4 1
A setFrom() 0 4 1
A getVideo() 0 4 1
A setVideo() 0 4 1
A getVoice() 0 4 1
A setVoice() 0 4 1
A setSupergroupChatCreated() 0 4 1
A isSupergroupChatCreated() 0 4 1
A setChannelChatCreated() 0 4 1
A isChannelChatCreated() 0 4 1
A setMigrateToChatId() 0 4 1
A getMigrateToChatId() 0 4 1
A setMigrateFromChatId() 0 4 1
A getMigrateFromChatId() 0 4 1
A getPinnedMessage() 0 4 1
A setPinnedMessage() 0 4 1
A getInvoice() 0 4 1
A setInvoice() 0 4 1
A getSuccessfulPayment() 0 4 1
A setSuccessfulPayment() 0 4 1

How to fix   Complexity   

Complex Class

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
2
namespace TelegramBot\Api\Types;
3
4
use TelegramBot\Api\BaseType;
5
use TelegramBot\Api\InvalidArgumentException;
6
use TelegramBot\Api\TypeInterface;
7
use TelegramBot\Api\Types\Payments\Invoice;
8
use TelegramBot\Api\Types\Payments\SuccessfulPayment;
9
10
class Message extends BaseType implements TypeInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     *
15
     * @var array
16
     */
17
    static protected $requiredParams = ['message_id', 'date', 'chat'];
18
19
    /**
20
     * {@inheritdoc}
21
     *
22
     * @var array
23
     */
24
    static protected $map = [
25
        'message_id' => true,
26
        'from' => User::class,
27
        'date' => true,
28
        'chat' => Chat::class,
29
        'forward_from' => User::class,
30
        'forward_date' => true,
31
        'reply_to_message' => Message::class,
32
        'text' => true,
33
        'entities' => ArrayOfMessageEntity::class,
34
        'audio' => Audio::class,
35
        'document' => Document::class,
36
        'photo' => ArrayOfPhotoSize::class,
37
        'sticker' => Sticker::class,
38
        'video' => Video::class,
39
        'voice' => Voice::class,
40
        'caption' => true,
41
        'contact' => Contact::class,
42
        'location' => Location::class,
43
        'venue' => Venue::class,
44
        'new_chat_member' => User::class,
45
        'left_chat_member' => User::class,
46
        'new_chat_title' => true,
47
        'new_chat_photo' => ArrayOfPhotoSize::class,
48
        'delete_chat_photo' => true,
49
        'group_chat_created' => true,
50
        'supergroup_chat_created' => true,
51
        'channel_chat_created' => true,
52
        'migrate_to_chat_id' => true,
53
        'migrate_from_chat_id' => true,
54
        'pinned_message' => Message::class,
55
        'invoice' => Invoice::class,
56
        'successful_payment' => SuccessfulPayment::class
57
    ];
58
59
    /**
60
     * Unique message identifier
61
     *
62
     * @var int
63
     */
64
    protected $messageId;
65
66
    /**
67
     * Optional. Sender name. Can be empty for messages sent to channels
68
     *
69
     * @var \TelegramBot\Api\Types\User
70
     */
71
    protected $from;
72
73
    /**
74
     * Date the message was sent in Unix time
75
     *
76
     * @var int
77
     */
78
    protected $date;
79
80
    /**
81
     * Conversation the message belongs to — user in case of a private message, GroupChat in case of a group
82
     *
83
     * @var \TelegramBot\Api\Types\Chat
84
     */
85
    protected $chat;
86
87
    /**
88
     * Optional. For forwarded messages, sender of the original message
89
     *
90
     * @var \TelegramBot\Api\Types\User
91
     */
92
    protected $forwardFrom;
93
94
    /**
95
     * Optional. For forwarded messages, date the original message was sent in Unix time
96
     *
97
     * @var int
98
     */
99
    protected $forwardDate;
100
101
    /**
102
     * Optional. For replies, the original message. Note that the Message object in this field will not contain further
103
     * reply_to_message fields even if it itself is a reply.
104
     *
105
     * @var \TelegramBot\Api\Types\Message
106
     */
107
    protected $replyToMessage;
108
109
    /**
110
     * Optional. For text messages, the actual UTF-8 text of the message
111
     *
112
     * @var string
113
     */
114
    protected $text;
115
116
    /**
117
     * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text.
118
     * array of \TelegramBot\Api\Types\MessageEntity
119
     *
120
     * @var array
121
     */
122
    protected $entities;
123
124
    /**
125
     * Optional. Message is an audio file, information about the file
126
     *
127
     * @var \TelegramBot\Api\Types\Audio
128
     */
129
    protected $audio;
130
131
    /**
132
     * Optional. Message is a general file, information about the file
133
     *
134
     * @var \TelegramBot\Api\Types\Document
135
     */
136
    protected $document;
137
138
    /**
139
     * Optional. Message is a photo, available sizes of the photo
140
     * array of \TelegramBot\Api\Types\Photo
141
     *
142
     * @var array
143
     */
144
    protected $photo;
145
146
    /**
147
     * Optional. Message is a sticker, information about the sticker
148
     *
149
     * @var \TelegramBot\Api\Types\Sticker
150
     */
151
    protected $sticker;
152
153
    /**
154
     * Optional. Message is a video, information about the video
155
     *
156
     * @var \TelegramBot\Api\Types\Video
157
     */
158
    protected $video;
159
160
    /**
161
     * Optional. Message is a voice message, information about the file
162
     *
163
     * @var \TelegramBot\Api\Types\Voice
164
     */
165
    protected $voice;
166
167
    /**
168
     * Optional. Message is a shared contact, information about the contact
169
     *
170
     * @var \TelegramBot\Api\Types\Contact
171
     */
172
    protected $contact;
173
174
    /**
175
     * Optional. Message is a shared location, information about the location
176
     *
177
     * @var \TelegramBot\Api\Types\Location
178
     */
179
    protected $location;
180
181
    /**
182
     * Optional. Message is a venue, information about the venue
183
     *
184
     * @var \TelegramBot\Api\Types\Venue
185
     */
186
    protected $venue;
187
188
    /**
189
     * Optional. A new member was added to the group, information about them (this member may be bot itself)
190
     *
191
     * @var \TelegramBot\Api\Types\User
192
     */
193
    protected $newChatMember;
194
195
    /**
196
     * Optional. A member was removed from the group, information about them (this member may be bot itself)
197
     *
198
     * @var \TelegramBot\Api\Types\User
199
     */
200
    protected $leftChatMember;
201
202
    /**
203
     * Optional. A group title was changed to this value
204
     *
205
     * @var string
206
     */
207
    protected $newChatTitle;
208
209
    /**
210
     * Optional. A group photo was change to this value
211
     *
212
     * @var mixed
213
     */
214
    protected $newChatPhoto;
215
216
    /**
217
     * Optional. Informs that the group photo was deleted
218
     *
219
     * @var bool
220
     */
221
    protected $deleteChatPhoto;
222
223
    /**
224
     * Optional. Informs that the group has been created
225
     *
226
     * @var bool
227
     */
228
    protected $groupChatCreated;
229
230
    /**
231
     * Optional. Text description of the video (usually empty)
232
     *
233
     * @var string
234
     */
235
    protected $caption;
236
237
238
    /**
239
     * Optional. Service message: the supergroup has been created
240
     *
241
     * @var bool
242
     */
243
    protected $supergroupChatCreated;
244
245
    /**
246
     * Optional. Service message: the channel has been created
247
     *
248
     * @var bool
249
     */
250
    protected $channelChatCreated;
251
252
    /**
253
     * Optional. The group has been migrated to a supergroup with the specified identifier,
254
     * not exceeding 1e13 by absolute value
255
     *
256
     * @var int
257
     */
258
    protected $migrateToChatId;
259
260
    /**
261
     * Optional. The supergroup has been migrated from a group with the specified identifier,
262
     * not exceeding 1e13 by absolute value
263
     *
264
     * @var int
265
     */
266
    protected $migrateFromChatId;
267
268
    /**
269
     * Optional. Specified message was pinned.Note that the Message object in this field
270
     * will not contain further reply_to_message fields even if it is itself a reply.
271
     *
272
     * @var Message
273
     */
274
    protected $pinnedMessage;
275
276
    /**
277
     * Optional. Message is an invoice for a payment, information about the invoice.
278
     *
279
     * @var Invoice
280
     */
281
    protected $invoice;
282
283
    /**
284
     * Optional. Message is a service message about a successful payment, information about the payment.
285
     *
286
     * @var SuccessfulPayment
287
     */
288
    protected $successfulPayment;
289
290
    /**
291
     * @return string
292
     */
293 1
    public function getCaption()
294
    {
295 1
        return $this->caption;
296
    }
297
298
    /**
299
     * @param string $caption
300
     */
301 2
    public function setCaption($caption)
302
    {
303 2
        $this->caption = $caption;
304 2
    }
305
306
    /**
307
     * @return Audio
308
     */
309 1
    public function getAudio()
310
    {
311 1
        return $this->audio;
312
    }
313
314
    /**
315
     * @param Audio $audio
316
     */
317 2
    public function setAudio(Audio $audio)
318
    {
319 2
        $this->audio = $audio;
320 2
    }
321
322
    /**
323
     * @return Chat
324
     */
325 2
    public function getChat()
326
    {
327 2
        return $this->chat;
328
    }
329
330
    /**
331
     * @param Chat $chat
332
     */
333 15
    public function setChat(Chat $chat)
334
    {
335 15
        $this->chat = $chat;
336 15
    }
337
338
    /**
339
     * @return Contact
340
     */
341 1
    public function getContact()
342
    {
343 1
        return $this->contact;
344
    }
345
346
    /**
347
     * @param Contact $contact
348
     */
349 2
    public function setContact(Contact $contact)
350
    {
351 2
        $this->contact = $contact;
352 2
    }
353
354
    /**
355
     * @return int
356
     */
357 1
    public function getDate()
358
    {
359 1
        return $this->date;
360
    }
361
362
    /**
363
     * @param int $date
364
     *
365
     * @throws InvalidArgumentException
366
     */
367 14
    public function setDate($date)
368
    {
369 14
        if (is_integer($date)) {
370 13
            $this->date = $date;
371 13
        } else {
372 1
            throw new InvalidArgumentException();
373
        }
374 13
    }
375
376
    /**
377
     * @return boolean
378
     */
379 1
    public function isDeleteChatPhoto()
380
    {
381 1
        return $this->deleteChatPhoto;
382
    }
383
384
    /**
385
     * @param boolean $deleteChatPhoto
386
     */
387 2
    public function setDeleteChatPhoto($deleteChatPhoto)
388
    {
389 2
        $this->deleteChatPhoto = (bool)$deleteChatPhoto;
390 2
    }
391
392
    /**
393
     * @return Document
394
     */
395 1
    public function getDocument()
396
    {
397 1
        return $this->document;
398
    }
399
400
    /**
401
     * @param Document $document
402
     */
403 2
    public function setDocument($document)
404
    {
405 2
        $this->document = $document;
406 2
    }
407
408
    /**
409
     * @return int
410
     */
411 1
    public function getForwardDate()
412
    {
413 1
        return $this->forwardDate;
414
    }
415
416
    /**
417
     * @param int $forwardDate
418
     *
419
     * @throws InvalidArgumentException
420
     */
421 3
    public function setForwardDate($forwardDate)
422
    {
423 3
        if (is_integer($forwardDate)) {
424 2
            $this->forwardDate = $forwardDate;
425 2
        } else {
426 1
            throw new InvalidArgumentException();
427
        }
428 2
    }
429
430
    /**
431
     * @return User
432
     */
433 1
    public function getForwardFrom()
434
    {
435 1
        return $this->forwardFrom;
436
    }
437
438
    /**
439
     * @param User $forwardFrom
440
     */
441 2
    public function setForwardFrom(User $forwardFrom)
442
    {
443 2
        $this->forwardFrom = $forwardFrom;
444 2
    }
445
446
    /**
447
     * @return boolean
448
     */
449 1
    public function isGroupChatCreated()
450
    {
451 1
        return $this->groupChatCreated;
452
    }
453
454
    /**
455
     * @param boolean $groupChatCreated
456
     */
457 2
    public function setGroupChatCreated($groupChatCreated)
458
    {
459 2
        $this->groupChatCreated = (bool)$groupChatCreated;
460 2
    }
461
462
    /**
463
     * @return User
464
     */
465 1
    public function getLeftChatMember()
466
    {
467 1
        return $this->leftChatMember;
468
    }
469
470
    /**
471
     * @param User $leftChatMember
472
     */
473 2
    public function setLeftChatMember($leftChatMember)
474
    {
475 2
        $this->leftChatMember = $leftChatMember;
476 2
    }
477
478
    /**
479
     * @return Location
480
     */
481 1
    public function getLocation()
482
    {
483 1
        return $this->location;
484
    }
485
486
    /**
487
     * @param Location $location
488
     */
489 2
    public function setLocation(Location $location)
490
    {
491 2
        $this->location = $location;
492 2
    }
493
494
    /**
495
     * @return Venue
496
     */
497
    public function getVenue()
498
    {
499
        return $this->venue;
500
    }
501
502
    /**
503
     * @param Venue $venue
504
     */
505
    public function setVenue($venue)
506
    {
507
        $this->venue = $venue;
508
    }
509
510
    /**
511
     * @return int
512
     */
513 1
    public function getMessageId()
514
    {
515 1
        return $this->messageId;
516
    }
517
518
    /**
519
     * @param int $messageId
520
     *
521
     * @throws InvalidArgumentException
522
     */
523 15
    public function setMessageId($messageId)
524
    {
525 15
        if (is_integer($messageId) || is_float($messageId)) {
526 14
            $this->messageId = $messageId;
0 ignored issues
show
Documentation Bug introduced by
It seems like $messageId can also be of type double. However, the property $messageId is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
527 14
        } else {
528 1
            throw new InvalidArgumentException();
529
        }
530 14
    }
531
532
    /**
533
     * @return User
534
     */
535 1
    public function getNewChatMember()
536
    {
537 1
        return $this->newChatMember;
538
    }
539
540
    /**
541
     * @param User $newChatMember
542
     */
543 2
    public function setNewChatMember($newChatMember)
544
    {
545 2
        $this->newChatMember = $newChatMember;
546 2
    }
547
548
    /**
549
     * @return array
550
     */
551 1
    public function getNewChatPhoto()
552
    {
553 1
        return $this->newChatPhoto;
554
    }
555
556
    /**
557
     * @param array $newChatPhoto
558
     */
559 2
    public function setNewChatPhoto($newChatPhoto)
560
    {
561 2
        $this->newChatPhoto = $newChatPhoto;
562 2
    }
563
564
    /**
565
     * @return string
566
     */
567 1
    public function getNewChatTitle()
568
    {
569 1
        return $this->newChatTitle;
570
    }
571
572
    /**
573
     * @param string $newChatTitle
574
     */
575 2
    public function setNewChatTitle($newChatTitle)
576
    {
577 2
        $this->newChatTitle = $newChatTitle;
578 2
    }
579
580
    /**
581
     * @return array
582
     */
583 1
    public function getPhoto()
584
    {
585 1
        return $this->photo;
586
    }
587
588
    /**
589
     * @param array $photo
590
     */
591 2
    public function setPhoto(array $photo)
592
    {
593 2
        $this->photo = $photo;
594 2
    }
595
596
    /**
597
     * @return Message
598
     */
599 1
    public function getReplyToMessage()
600
    {
601 1
        return $this->replyToMessage;
602
    }
603
604
    /**
605
     * @param Message $replyToMessage
606
     */
607 2
    public function setReplyToMessage(Message $replyToMessage)
608
    {
609 2
        $this->replyToMessage = $replyToMessage;
610 2
    }
611
612
    /**
613
     * @return Sticker
614
     */
615 1
    public function getSticker()
616
    {
617 1
        return $this->sticker;
618
    }
619
620
    /**
621
     * @param Sticker $sticker
622
     */
623 2
    public function setSticker(Sticker $sticker)
624
    {
625 2
        $this->sticker = $sticker;
626 2
    }
627
628
    /**
629
     * @return string
630
     */
631 7
    public function getText()
632
    {
633 7
        return $this->text;
634
    }
635
636
    /**
637
     * @param string $text
638
     */
639 5
    public function setText($text)
640
    {
641 5
        $this->text = $text;
642 5
    }
643
644
    /**
645
     * @return array
646
     */
647
    public function getEntities()
648
    {
649
        return $this->entities;
650
    }
651
652
    /**
653
     * @param array $entities
654
     */
655 1
    public function setEntities($entities)
656
    {
657 1
        $this->entities = $entities;
658 1
    }
659
660
    /**
661
     * @return User
662
     */
663 1
    public function getFrom()
664
    {
665 1
        return $this->from;
666
    }
667
668
    /**
669
     * @param User $from
670
     */
671 13
    public function setFrom(User $from)
672
    {
673 13
        $this->from = $from;
674 13
    }
675
676
    /**
677
     * @return Video
678
     */
679 1
    public function getVideo()
680
    {
681 1
        return $this->video;
682
    }
683
684
    /**
685
     * @param Video $video
686
     */
687 2
    public function setVideo(Video $video)
688
    {
689 2
        $this->video = $video;
690 2
    }
691
692
    /**
693
     * @return Voice
694
     */
695 1
    public function getVoice()
696
    {
697 1
        return $this->voice;
698
    }
699
700
    /**
701
     * @param Voice $voice
702
     */
703 2
    public function setVoice($voice)
704
    {
705 2
        $this->voice = $voice;
706 2
    }
707
708
    /**
709
     * @param boolean $supergroupChatCreated
710
     */
711 2
    public function setSupergroupChatCreated($supergroupChatCreated)
712
    {
713 2
        $this->supergroupChatCreated = $supergroupChatCreated;
714 2
    }
715
716
    /**
717
     * @return boolean
718
     */
719 1
    public function isSupergroupChatCreated()
720
    {
721 1
        return $this->supergroupChatCreated;
722
    }
723
724
    /**
725
     * @param boolean $channelChatCreated
726
     */
727 2
    public function setChannelChatCreated($channelChatCreated)
728
    {
729 2
        $this->channelChatCreated = $channelChatCreated;
730 2
    }
731
732
    /**
733
     * @return boolean
734
     */
735 1
    public function isChannelChatCreated()
736
    {
737 1
        return $this->channelChatCreated;
738
    }
739
740
    /**
741
     * @param int $migrateToChatId
742
     */
743 2
    public function setMigrateToChatId($migrateToChatId)
744
    {
745 2
        $this->migrateToChatId = $migrateToChatId;
746 2
    }
747
748
    /**
749
     * @return int
750
     */
751 1
    public function getMigrateToChatId()
752
    {
753 1
        return $this->migrateToChatId;
754
    }
755
756
    /**
757
     * @param int $migrateFromChatId
758
     */
759 4
    public function setMigrateFromChatId($migrateFromChatId)
760
    {
761 4
        $this->migrateFromChatId = $migrateFromChatId;
762 4
    }
763
764
    /**
765
     * @return int
766
     */
767 1
    public function getMigrateFromChatId()
768
    {
769 1
        return $this->migrateFromChatId;
770
    }
771
772
    /**
773
     * @return Message
774
     */
775
    public function getPinnedMessage()
776
    {
777
        return $this->pinnedMessage;
778
    }
779
780
    /**
781
     * @param Message $pinnedMessage
782
     */
783
    public function setPinnedMessage($pinnedMessage)
784
    {
785
        $this->pinnedMessage = $pinnedMessage;
786
    }
787
788
    /**
789
     * @author MY
790
     * @return Invoice
791
     */
792
    public function getInvoice()
793
    {
794
        return $this->invoice;
795
    }
796
797
    /**
798
     * @author MY
799
     * @param Invoice $invoice
800
     */
801
    public function setInvoice($invoice)
802
    {
803
        $this->invoice = $invoice;
804
    }
805
806
    /**
807
     * @author MY
808
     * @return SuccessfulPayment
809
     */
810
    public function getSuccessfulPayment()
811
    {
812
        return $this->successfulPayment;
813
    }
814
815
    /**
816
     * @author MY
817
     * @param SuccessfulPayment $successfulPayment
818
     */
819
    public function setSuccessfulPayment($successfulPayment)
820
    {
821
        $this->successfulPayment = $successfulPayment;
822
    }
823
}
824