Passed
Pull Request — master (#211)
by
unknown
04:27
created

Message::getAudio()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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
        'caption_entities' => ArrayOfMessageEntity::class,
35
        'audio' => Audio::class,
36
        'document' => Document::class,
37
        'photo' => ArrayOfPhotoSize::class,
38
        'sticker' => Sticker::class,
39
        'video' => Video::class,
40
        'animation' => Animation::class,
41
        'voice' => Voice::class,
42
        'caption' => true,
43
        'contact' => Contact::class,
44
        'location' => Location::class,
45
        'venue' => Venue::class,
46
        'new_chat_member' => User::class,
47
        'left_chat_member' => User::class,
48
        'new_chat_title' => true,
49
        'new_chat_photo' => ArrayOfPhotoSize::class,
50
        'delete_chat_photo' => true,
51
        'group_chat_created' => true,
52
        'supergroup_chat_created' => true,
53
        'channel_chat_created' => true,
54
        'migrate_to_chat_id' => true,
55
        'migrate_from_chat_id' => true,
56
        'pinned_message' => Message::class,
57
        'invoice' => Invoice::class,
58
        'successful_payment' => SuccessfulPayment::class,
59
        'forward_signature' => true,
60
        'author_signature' => true,
61
        'connected_website' => true
62
    ];
63
64
    /**
65
     * Unique message identifier
66
     *
67
     * @var int
68
     */
69
    protected $messageId;
70
71
    /**
72
     * Optional. Sender name. Can be empty for messages sent to channels
73
     *
74
     * @var \TelegramBot\Api\Types\User
75
     */
76
    protected $from;
77
78
    /**
79
     * Date the message was sent in Unix time
80
     *
81
     * @var int
82
     */
83
    protected $date;
84
85
    /**
86
     * Conversation the message belongs to — user in case of a private message, GroupChat in case of a group
87
     *
88
     * @var \TelegramBot\Api\Types\Chat
89
     */
90
    protected $chat;
91
92
    /**
93
     * Optional. For forwarded messages, sender of the original message
94
     *
95
     * @var \TelegramBot\Api\Types\User
96
     */
97
    protected $forwardFrom;
98
99
    /**
100
     * Optional. For forwarded messages, date the original message was sent in Unix time
101
     *
102
     * @var int
103
     */
104
    protected $forwardDate;
105
106
    /**
107
     * Optional. For replies, the original message. Note that the Message object in this field will not contain further
108
     * reply_to_message fields even if it itself is a reply.
109
     *
110
     * @var \TelegramBot\Api\Types\Message
111
     */
112
    protected $replyToMessage;
113
114
    /**
115
     * Optional. For text messages, the actual UTF-8 text of the message
116
     *
117
     * @var string
118
     */
119
    protected $text;
120
121
    /**
122
     * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text.
123
     * array of \TelegramBot\Api\Types\MessageEntity
124
     *
125
     * @var array
126
     */
127
    protected $entities;
128
129
    /**
130
     * Optional. Message is an audio file, information about the file
131
     *
132
     * @var \TelegramBot\Api\Types\Audio
133
     */
134
    protected $audio;
135
136
    /**
137
     * Optional. Message is a general file, information about the file
138
     *
139
     * @var \TelegramBot\Api\Types\Document
140
     */
141
    protected $document;
142
143
    /**
144
     * Optional. Message is a photo, available sizes of the photo
145
     * array of \TelegramBot\Api\Types\Photo
146
     *
147
     * @var array
148
     */
149
    protected $photo;
150
151
    /**
152
     * Optional. Message is a sticker, information about the sticker
153
     *
154
     * @var \TelegramBot\Api\Types\Sticker
155
     */
156
    protected $sticker;
157
158
    /**
159
     * Optional. Message is a video, information about the video
160
     *
161
     * @var \TelegramBot\Api\Types\Video
162
     */
163
    protected $video;
164
    
165
    /**
166
     * Optional. Message is a animation, information about the animation
167
     *
168
     * @var \TelegramBot\Api\Types\Animation
169
     */
170
    protected $animation;
171
172
    /**
173
     * Optional. Message is a voice message, information about the file
174
     *
175
     * @var \TelegramBot\Api\Types\Voice
176
     */
177
    protected $voice;
178
179
    /**
180
     * Optional. Message is a shared contact, information about the contact
181
     *
182
     * @var \TelegramBot\Api\Types\Contact
183
     */
184
    protected $contact;
185
186
    /**
187
     * Optional. Message is a shared location, information about the location
188
     *
189
     * @var \TelegramBot\Api\Types\Location
190
     */
191
    protected $location;
192
193
    /**
194
     * Optional. Message is a venue, information about the venue
195
     *
196
     * @var \TelegramBot\Api\Types\Venue
197
     */
198
    protected $venue;
199
200
    /**
201
     * Optional. A new member was added to the group, information about them (this member may be bot itself)
202
     *
203
     * @var \TelegramBot\Api\Types\User
204
     */
205
    protected $newChatMember;
206
207
    /**
208
     * Optional. A member was removed from the group, information about them (this member may be bot itself)
209
     *
210
     * @var \TelegramBot\Api\Types\User
211
     */
212
    protected $leftChatMember;
213
214
    /**
215
     * Optional. A group title was changed to this value
216
     *
217
     * @var string
218
     */
219
    protected $newChatTitle;
220
221
    /**
222
     * Optional. A group photo was change to this value
223
     *
224
     * @var mixed
225
     */
226
    protected $newChatPhoto;
227
228
    /**
229
     * Optional. Informs that the group photo was deleted
230
     *
231
     * @var bool
232
     */
233
    protected $deleteChatPhoto;
234
235
    /**
236
     * Optional. Informs that the group has been created
237
     *
238
     * @var bool
239
     */
240
    protected $groupChatCreated;
241
242
    /**
243
     * Optional. Text description of the video (usually empty)
244
     *
245
     * @var string
246
     */
247
    protected $caption;
248
249
250
    /**
251
     * Optional. Service message: the supergroup has been created
252
     *
253
     * @var bool
254
     */
255
    protected $supergroupChatCreated;
256
257
    /**
258
     * Optional. Service message: the channel has been created
259
     *
260
     * @var bool
261
     */
262
    protected $channelChatCreated;
263
264
    /**
265
     * Optional. The group has been migrated to a supergroup with the specified identifier,
266
     * not exceeding 1e13 by absolute value
267
     *
268
     * @var int
269
     */
270
    protected $migrateToChatId;
271
272
    /**
273
     * Optional. The supergroup has been migrated from a group with the specified identifier,
274
     * not exceeding 1e13 by absolute value
275
     *
276
     * @var int
277
     */
278
    protected $migrateFromChatId;
279
280
    /**
281
     * Optional. Specified message was pinned.Note that the Message object in this field
282
     * will not contain further reply_to_message fields even if it is itself a reply.
283
     *
284
     * @var Message
285
     */
286
    protected $pinnedMessage;
287
288
    /**
289
     * Optional. Message is an invoice for a payment, information about the invoice.
290
     *
291
     * @var Invoice
292
     */
293
    protected $invoice;
294
295
    /**
296
     * Optional. Message is a service message about a successful payment, information about the payment.
297
     *
298
     * @var SuccessfulPayment
299
     */
300
    protected $successfulPayment;
301
302
    /**
303
     * Optional. For messages forwarded from channels, signature of the post author if present
304
     *
305
     * @var string
306
     */
307
    protected $forwardSignature;
308
309
    /**
310
     * Optional. Signature of the post author for messages in channels
311
     *
312
     * @var string
313
     */
314
    protected $authorSignature;
315
316
    /**
317
     * Optional. For messages with a caption, special entities like usernames,
318
     * URLs, bot commands, etc. that appear in the caption
319
     *
320
     * @var ArrayOfMessageEntity
321
     */
322
    protected $captionEntities;
323
324
    /**
325
     * Optional. The domain name of the website on which the user has logged in.
326
     *
327
     * @var string
328
     */
329
    protected $connectedWebsite;
330
331
    /**
332
     * @return string
333
     */
334 1
    public function getCaption()
335
    {
336 1
        return $this->caption;
337
    }
338
339
    /**
340
     * @param string $caption
341
     */
342 2
    public function setCaption($caption)
343
    {
344 2
        $this->caption = $caption;
345 2
    }
346
347
    /**
348
     * @return Audio
349
     */
350 1
    public function getAudio()
351
    {
352 1
        return $this->audio;
353
    }
354
355
    /**
356
     * @param Audio $audio
357
     */
358 2
    public function setAudio(Audio $audio)
359
    {
360 2
        $this->audio = $audio;
361 2
    }
362
363
    /**
364
     * @return Chat
365
     */
366 2
    public function getChat()
367
    {
368 2
        return $this->chat;
369
    }
370
371
    /**
372
     * @param Chat $chat
373
     */
374 15
    public function setChat(Chat $chat)
375
    {
376 15
        $this->chat = $chat;
377 15
    }
378
379
    /**
380
     * @return Contact
381
     */
382 1
    public function getContact()
383
    {
384 1
        return $this->contact;
385
    }
386
387
    /**
388
     * @param Contact $contact
389
     */
390 2
    public function setContact(Contact $contact)
391
    {
392 2
        $this->contact = $contact;
393 2
    }
394
395
    /**
396
     * @return int
397
     */
398 1
    public function getDate()
399
    {
400 1
        return $this->date;
401
    }
402
403
    /**
404
     * @param int $date
405
     *
406
     * @throws InvalidArgumentException
407
     */
408 14
    public function setDate($date)
409
    {
410 14
        if (is_integer($date)) {
411 13
            $this->date = $date;
412 13
        } else {
413 1
            throw new InvalidArgumentException();
414
        }
415 13
    }
416
417
    /**
418
     * @return boolean
419
     */
420 1
    public function isDeleteChatPhoto()
421
    {
422 1
        return $this->deleteChatPhoto;
423
    }
424
425
    /**
426
     * @param boolean $deleteChatPhoto
427
     */
428 2
    public function setDeleteChatPhoto($deleteChatPhoto)
429
    {
430 2
        $this->deleteChatPhoto = (bool)$deleteChatPhoto;
431 2
    }
432
433
    /**
434
     * @return Document
435
     */
436 1
    public function getDocument()
437
    {
438 1
        return $this->document;
439
    }
440
441
    /**
442
     * @param Document $document
443
     */
444 2
    public function setDocument($document)
445
    {
446 2
        $this->document = $document;
447 2
    }
448
449
    /**
450
     * @return int
451
     */
452 1
    public function getForwardDate()
453
    {
454 1
        return $this->forwardDate;
455
    }
456
457
    /**
458
     * @param int $forwardDate
459
     *
460
     * @throws InvalidArgumentException
461
     */
462 3
    public function setForwardDate($forwardDate)
463
    {
464 3
        if (is_integer($forwardDate)) {
465 2
            $this->forwardDate = $forwardDate;
466 2
        } else {
467 1
            throw new InvalidArgumentException();
468
        }
469 2
    }
470
471
    /**
472
     * @return User
473
     */
474 1
    public function getForwardFrom()
475
    {
476 1
        return $this->forwardFrom;
477
    }
478
479
    /**
480
     * @param User $forwardFrom
481
     */
482 2
    public function setForwardFrom(User $forwardFrom)
483
    {
484 2
        $this->forwardFrom = $forwardFrom;
485 2
    }
486
487
    /**
488
     * @return boolean
489
     */
490 1
    public function isGroupChatCreated()
491
    {
492 1
        return $this->groupChatCreated;
493
    }
494
495
    /**
496
     * @param boolean $groupChatCreated
497
     */
498 2
    public function setGroupChatCreated($groupChatCreated)
499
    {
500 2
        $this->groupChatCreated = (bool)$groupChatCreated;
501 2
    }
502
503
    /**
504
     * @return User
505
     */
506 1
    public function getLeftChatMember()
507
    {
508 1
        return $this->leftChatMember;
509
    }
510
511
    /**
512
     * @param User $leftChatMember
513
     */
514 2
    public function setLeftChatMember($leftChatMember)
515
    {
516 2
        $this->leftChatMember = $leftChatMember;
517 2
    }
518
519
    /**
520
     * @return Location
521
     */
522 1
    public function getLocation()
523
    {
524 1
        return $this->location;
525
    }
526
527
    /**
528
     * @param Location $location
529
     */
530 2
    public function setLocation(Location $location)
531
    {
532 2
        $this->location = $location;
533 2
    }
534
535
    /**
536
     * @return Venue
537
     */
538
    public function getVenue()
539
    {
540
        return $this->venue;
541
    }
542
543
    /**
544
     * @param Venue $venue
545
     */
546
    public function setVenue($venue)
547
    {
548
        $this->venue = $venue;
549
    }
550
551
    /**
552
     * @return int
553
     */
554 1
    public function getMessageId()
555
    {
556 1
        return $this->messageId;
557
    }
558
559
    /**
560
     * @param int $messageId
561
     *
562
     * @throws InvalidArgumentException
563
     */
564 15
    public function setMessageId($messageId)
565
    {
566 15
        if (is_integer($messageId) || is_float($messageId)) {
567 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...
568 14
        } else {
569 1
            throw new InvalidArgumentException();
570
        }
571 14
    }
572
573
    /**
574
     * @return User
575
     */
576 1
    public function getNewChatMember()
577
    {
578 1
        return $this->newChatMember;
579
    }
580
581
    /**
582
     * @param User $newChatMember
583
     */
584 2
    public function setNewChatMember($newChatMember)
585
    {
586 2
        $this->newChatMember = $newChatMember;
587 2
    }
588
589
    /**
590
     * @return array
591
     */
592 1
    public function getNewChatPhoto()
593
    {
594 1
        return $this->newChatPhoto;
595
    }
596
597
    /**
598
     * @param array $newChatPhoto
599
     */
600 2
    public function setNewChatPhoto($newChatPhoto)
601
    {
602 2
        $this->newChatPhoto = $newChatPhoto;
603 2
    }
604
605
    /**
606
     * @return string
607
     */
608 1
    public function getNewChatTitle()
609
    {
610 1
        return $this->newChatTitle;
611
    }
612
613
    /**
614
     * @param string $newChatTitle
615
     */
616 2
    public function setNewChatTitle($newChatTitle)
617
    {
618 2
        $this->newChatTitle = $newChatTitle;
619 2
    }
620
621
    /**
622
     * @return array
623
     */
624 1
    public function getPhoto()
625
    {
626 1
        return $this->photo;
627
    }
628
629
    /**
630
     * @param array $photo
631
     */
632 2
    public function setPhoto(array $photo)
633
    {
634 2
        $this->photo = $photo;
635 2
    }
636
637
    /**
638
     * @return Message
639
     */
640 1
    public function getReplyToMessage()
641
    {
642 1
        return $this->replyToMessage;
643
    }
644
645
    /**
646
     * @param Message $replyToMessage
647
     */
648 2
    public function setReplyToMessage(Message $replyToMessage)
649
    {
650 2
        $this->replyToMessage = $replyToMessage;
651 2
    }
652
653
    /**
654
     * @return Sticker
655
     */
656 1
    public function getSticker()
657
    {
658 1
        return $this->sticker;
659
    }
660
661
    /**
662
     * @param Sticker $sticker
663
     */
664 2
    public function setSticker(Sticker $sticker)
665
    {
666 2
        $this->sticker = $sticker;
667 2
    }
668
669
    /**
670
     * @return string
671
     */
672 7
    public function getText()
673
    {
674 7
        return $this->text;
675
    }
676
677
    /**
678
     * @param string $text
679
     */
680 5
    public function setText($text)
681
    {
682 5
        $this->text = $text;
683 5
    }
684
685
    /**
686
     * @return array
687
     */
688
    public function getEntities()
689
    {
690
        return $this->entities;
691
    }
692
693
    /**
694
     * @param array $entities
695
     */
696 1
    public function setEntities($entities)
697
    {
698 1
        $this->entities = $entities;
699 1
    }
700
701
    /**
702
     * @return User
703
     */
704 1
    public function getFrom()
705
    {
706 1
        return $this->from;
707
    }
708
709
    /**
710
     * @param User $from
711
     */
712 13
    public function setFrom(User $from)
713
    {
714 13
        $this->from = $from;
715 13
    }
716
717
    /**
718
     * @return Video
719
     */
720 1
    public function getVideo()
721
    {
722 1
        return $this->video;
723
    }
724
725
    /**
726
     * @param Video $video
727
     */
728 2
    public function setVideo(Video $video)
729
    {
730 2
        $this->video = $video;
731 2
    }
732
    
733
    /**
734
     * @return Animation
735
     */
736
    public function getAnimation()
737
    {
738
        return $this->animation;
739
    }
740
741
    /**
742
     * @param Animation $animation
743
     */
744
    public function setAnimation(Animation $animation)
745
    {
746
        $this->animation = $animation;
747
    }
748
749
    /**
750
     * @return Voice
751
     */
752 1
    public function getVoice()
753
    {
754 1
        return $this->voice;
755
    }
756
757
    /**
758
     * @param Voice $voice
759
     */
760 2
    public function setVoice($voice)
761
    {
762 2
        $this->voice = $voice;
763 2
    }
764
765
    /**
766
     * @param boolean $supergroupChatCreated
767
     */
768 2
    public function setSupergroupChatCreated($supergroupChatCreated)
769
    {
770 2
        $this->supergroupChatCreated = $supergroupChatCreated;
771 2
    }
772
773
    /**
774
     * @return boolean
775
     */
776 1
    public function isSupergroupChatCreated()
777
    {
778 1
        return $this->supergroupChatCreated;
779
    }
780
781
    /**
782
     * @param boolean $channelChatCreated
783
     */
784 2
    public function setChannelChatCreated($channelChatCreated)
785
    {
786 2
        $this->channelChatCreated = $channelChatCreated;
787 2
    }
788
789
    /**
790
     * @return boolean
791
     */
792 1
    public function isChannelChatCreated()
793
    {
794 1
        return $this->channelChatCreated;
795
    }
796
797
    /**
798
     * @param int $migrateToChatId
799
     */
800 2
    public function setMigrateToChatId($migrateToChatId)
801
    {
802 2
        $this->migrateToChatId = $migrateToChatId;
803 2
    }
804
805
    /**
806
     * @return int
807
     */
808 1
    public function getMigrateToChatId()
809
    {
810 1
        return $this->migrateToChatId;
811
    }
812
813
    /**
814
     * @param int $migrateFromChatId
815
     */
816 4
    public function setMigrateFromChatId($migrateFromChatId)
817
    {
818 4
        $this->migrateFromChatId = $migrateFromChatId;
819 4
    }
820
821
    /**
822
     * @return int
823
     */
824 1
    public function getMigrateFromChatId()
825
    {
826 1
        return $this->migrateFromChatId;
827
    }
828
829
    /**
830
     * @return Message
831
     */
832
    public function getPinnedMessage()
833
    {
834
        return $this->pinnedMessage;
835
    }
836
837
    /**
838
     * @param Message $pinnedMessage
839
     */
840
    public function setPinnedMessage($pinnedMessage)
841
    {
842
        $this->pinnedMessage = $pinnedMessage;
843
    }
844
845
    /**
846
     * @author MY
847
     * @return Invoice
848
     */
849
    public function getInvoice()
850
    {
851
        return $this->invoice;
852
    }
853
854
    /**
855
     * @author MY
856
     * @param Invoice $invoice
857
     */
858
    public function setInvoice($invoice)
859
    {
860
        $this->invoice = $invoice;
861
    }
862
863
    /**
864
     * @author MY
865
     * @return SuccessfulPayment
866
     */
867
    public function getSuccessfulPayment()
868
    {
869
        return $this->successfulPayment;
870
    }
871
872
    /**
873
     * @author MY
874
     * @param SuccessfulPayment $successfulPayment
875
     */
876
    public function setSuccessfulPayment($successfulPayment)
877
    {
878
        $this->successfulPayment = $successfulPayment;
879
    }
880
881
    /**
882
     * @return string
883
     */
884
    public function getForwardSignature()
885
    {
886
        return $this->forwardSignature;
887
    }
888
889
    /**
890
     * @param string $forwardSignature
891
     */
892
    public function setForwardSignature($forwardSignature)
893
    {
894
        $this->forwardSignature = $forwardSignature;
895
    }
896
897
    /**
898
     * @return string
899
     */
900
    public function getAuthorSignature()
901
    {
902
        return $this->authorSignature;
903
    }
904
905
    /**
906
     * @param string $authorSignature
907
     */
908
    public function setAuthorSignature($authorSignature)
909
    {
910
        $this->authorSignature = $authorSignature;
911
    }
912
913
    /**
914
     * @return ArrayOfMessageEntity
915
     */
916
    public function getCaptionEntities()
917
    {
918
        return $this->captionEntities;
919
    }
920
921
    /**
922
     * @param ArrayOfMessageEntity $captionEntities
923
     */
924
    public function setCaptionEntities($captionEntities)
925
    {
926
        $this->captionEntities = $captionEntities;
927
    }
928
929
    /**
930
     * @return string
931
     */
932
    public function getConnectedWebsite()
933
    {
934
        return $this->connectedWebsite;
935
    }
936
937
    /**
938
     * @param string $connectedWebsite
939
     */
940
    public function setConnectedWebsite($connectedWebsite)
941
    {
942
        $this->connectedWebsite = $connectedWebsite;
943
    }
944
}
945