Completed
Push — master ( 15e507...ea07c8 )
by Camilo
05:47 queued 02:02
created

Message   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 260
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 11

Test Coverage

Coverage 60%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 17
lcom 0
cbo 11
dl 0
loc 260
ccs 21
cts 35
cp 0.6
rs 10
c 6
b 1
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
F __construct() 0 71 16
A mapSubObjects() 0 20 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 17 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\Telegram\Types;
6
7
use unreal4u\InternalFunctionality\AbstractFiller;
8
use unreal4u\Telegram\Types\Custom\PhotoSizeArray;
9
10
/**
11
 * This object represents a message.
12
 *
13
 * Objects defined as-is december 2015
14
 *
15
 * @see https://core.telegram.org/bots/api#message
16
 */
17
class Message extends AbstractFiller
18
{
19
    /**
20
     * Unique message identifier
21
     * @var int
22
     */
23
    public $message_id = 0;
24
25
    /**
26
     * Optional. Sender, can be empty for messages sent to channels
27
     * @var User
28
     */
29
    public $from = null;
30
31
    /**
32
     * Date the message was sent in Unix time
33
     * @var int
34
     */
35
    public $date = 0;
36
37
    /**
38
     * Conversation the message belongs to
39
     * @var Chat
40
     */
41
    public $chat = null;
42
43
    /**
44
     * Optional. For forwarded messages, sender of the original message
45
     * @var User
46
     */
47
    public $forward_from = null;
48
49
    /**
50
     * Optional. For forwarded messages, date the original message was sent in Unix time
51
     * @var int
52
     */
53
    public $forward_date = 0;
54
55
    /**
56
     * Optional. For replies, the original message. Note that the Message object in this field will not contain further
57
     * reply_to_message fields even if it itself is a reply.
58
     * @var Message
59
     */
60
    public $reply_to_message = null;
61
62
    /**
63
     * Optional. For text messages, the actual UTF-8 text of the message
64
     * @var string
65
     */
66
    public $text = '';
67
68
    /**
69
     * Optional. Message is an audio file, information about the file
70
     * @var Audio
71
     */
72
    public $audio = null;
73
74
    /**
75
     * Optional. Message is a general file, information about the file
76
     * @var Document
77
     */
78
    public $document = null;
79
80
    /**
81
     * Optional. Message is a photo, available sizes of the photo
82
     * @var array
83
     */
84
    public $photo = [];
85
86
    /**
87
     * Optional. Message is a sticker, information about the sticker
88
     * @var Sticker
89
     */
90
    public $sticker = null;
91
92
    /**
93
     * Optional. Message is a video, information about the video
94
     * @var Video
95
     */
96
    public $video = null;
97
98
    /**
99
     * Optional. Message is a voice message, information about the file
100
     * @var Voice
101
     */
102
    public $voice = null;
103
104
    /**
105
     * Optional. Caption for the photo or video
106
     * @var string
107
     */
108
    public $caption = '';
109
110
    /**
111
     * Optional. Message is a shared contact, information about the contact
112
     * @var Contact
113
     */
114
    public $contact = null;
115
116
    /**
117
     * Optional. Message is a shared location, information about the location
118
     * @var Location
119
     */
120
    public $location = null;
121
122
    /**
123
     * Optional. A new member was added to the group, information about them (this member may be the bot itself)
124
     * @var User
125
     */
126
    public $new_chat_participant = null;
127
128
    /**
129
     * Optional. A member was removed from the group, information about them (this member may be the bot itself)
130
     * @var User
131
     */
132
    public $left_chat_participant = null;
133
134
    /**
135
     * Optional. A chat title was changed to this value
136
     * @var string
137
     */
138
    public $new_chat_title = '';
139
140
    /**
141
     * Optional. A chat photo was change to this value
142
     * @var array
143
     */
144
    public $new_chat_photo = [];
145
146
    /**
147
     * Optional. Service message: the chat photo was deleted
148
     * @var bool
149
     */
150
    public $delete_chat_photo = false;
151
152
    /**
153
     * Optional. Service message: the group has been created
154
     * @var bool
155
     */
156
    public $group_chat_created = false;
157
158
    /**
159
     * Optional. Service message: the supergroup has been created
160
     * @var bool
161
     */
162
    public $supergroup_chat_created = false;
163
164
    /**
165
     * Optional. Service message: the channel has been created
166
     * @var bool
167
     */
168
    public $channel_chat_created = false;
169
170
    /**
171
     * Optional. The group has been migrated to a supergroup with the specified identifier, not exceeding 1e13 by
172
     * absolute value
173
     * @var int
174
     */
175
    public $migrate_to_chat_id = 0;
176
177
    /**
178
     * Optional. The supergroup has been migrated from a group with the specified identifier, not exceeding 1e13 by
179
     * absolute value
180
     * @var int
181
     */
182
    public $migrate_from_chat_id = 0;
183
184 4
    public function __construct(\stdClass $data = null)
185
    {
186
        // From is of User type of data
187 4
        if (!empty($data->from)) {
188 4
            $data->from = new User($data->from);
189
        }
190
191
        // Chat always should be a chat object
192 4
        if (!empty($data->chat)) {
193 4
            $data->chat = new Chat($data->chat);
194
        }
195
196
        // forward_from == User object
197 4
        if (!empty($data->forward_from)) {
198
            $data->forward_from = new User($data->forward_from);
199
        }
200
201
        // reply_to_message == Message object
202 4
        if (!empty($data->reply_to_message)) {
203
            $data->reply_to_message = new Message($data->reply_to_message);
204
        }
205
206
        // ... etc
207 4
        if (!empty($data->audio)) {
208
            $data->audio = new Audio($data->audio);
209
        }
210
211 4
        if (!empty($data->document)) {
212
            $data->document = new Document($data->document);
213
        }
214
215 4
        if (!empty($data->photo)) {
216
            $photoArray = new PhotoSizeArray($data->photo);
217
            $data->photo = $photoArray->data;
218
        }
219
220 4
        if (!empty($data->sticker)) {
221
            $data->sticker = new Sticker($data->sticker);
222
        }
223
224 4
        if (!empty($data->video)) {
225
            $data->video = new Video($data->video);
226
        }
227
228 4
        if (!empty($data->voice)) {
229
            $data->voice = new Voice($data->voice);
230
        }
231
232 4
        if (!empty($data->contact)) {
233
            $data->contact = new Contact($data->contact);
234
        }
235
236 4
        if (!empty($data->location)) {
237 1
            $data->location = new Location($data->location);
238
        }
239
240 4
        if (!empty($data->new_chat_participant)) {
241
            $data->new_chat_participant = new User($data->new_chat_participant);
242
        }
243
244 4
        if (!empty($data->left_chat_participant)) {
245
            $data->left_chat_participant = new User($data->left_chat_participant);
246
        }
247
248 4
        if (!empty($data->new_chat_photo)) {
249
            $photoArray = new PhotoSizeArray($data->new_chat_photo);
250
            $data->new_chat_photo = $photoArray->data;
251
        }
252
253 4
        parent::__construct($data);
254 4
    }
255
256
    protected function mapSubObjects(): array
257
    {
258
        return [
259
            'from' => 'User',
260
            'chat' => 'Chat',
261
            'forward_from' => 'User',
262
            'reply_to_message' => 'Message',
263
            'audio' => 'Audio',
264
            'document' => 'Document',
265
            'photo' => 'PhotoSizeArray', // Special case!
266
            'sticker' => 'Sticker',
267
            'video' => 'Video',
268
            'voice' => 'Voice',
269
            'contact' => 'Contact',
270
            'location' => 'Location',
271
            'new_chat_participant' => 'User',
272
            'left_chat_participant' => 'User',
273
            'new_chat_photo' => 'PhotoSizeArray', // Special case!
274
        ];
275
    }
276
}
277