Message::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 25
nc 1
nop 25
dl 0
loc 52
rs 9.52
c 0
b 0
f 0

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/**
4
 * This phpFile is auto-generated.
5
 */
6
7
declare(strict_types=1);
8
9
namespace AurimasNiekis\TdLibSchema;
10
11
/**
12
 * Describes a message.
13
 */
14
class Message extends TdObject
15
{
16
    public const TYPE_NAME = 'message';
17
18
    /**
19
     * Message identifier, unique for the chat to which the message belongs.
20
     *
21
     * @var int
22
     */
23
    protected int $id;
24
25
    /**
26
     * Identifier of the user who sent the message; 0 if unknown. Currently, it is unknown for channel posts and for channel posts automatically forwarded to discussion group.
27
     *
28
     * @var int
29
     */
30
    protected int $senderUserId;
31
32
    /**
33
     * Chat identifier.
34
     *
35
     * @var int
36
     */
37
    protected int $chatId;
38
39
    /**
40
     * Information about the sending state of the message; may be null.
41
     *
42
     * @var MessageSendingState|null
43
     */
44
    protected ?MessageSendingState $sendingState;
45
46
    /**
47
     * Information about the scheduling state of the message; may be null.
48
     *
49
     * @var MessageSchedulingState|null
50
     */
51
    protected ?MessageSchedulingState $schedulingState;
52
53
    /**
54
     * True, if the message is outgoing.
55
     *
56
     * @var bool
57
     */
58
    protected bool $isOutgoing;
59
60
    /**
61
     * True, if the message can be edited. For live location and poll messages this fields shows whether editMessageLiveLocation or stopPoll can be used with this message by the client.
62
     *
63
     * @var bool
64
     */
65
    protected bool $canBeEdited;
66
67
    /**
68
     * True, if the message can be forwarded.
69
     *
70
     * @var bool
71
     */
72
    protected bool $canBeForwarded;
73
74
    /**
75
     * True, if the message can be deleted only for the current user while other users will continue to see it.
76
     *
77
     * @var bool
78
     */
79
    protected bool $canBeDeletedOnlyForSelf;
80
81
    /**
82
     * True, if the message can be deleted for all users.
83
     *
84
     * @var bool
85
     */
86
    protected bool $canBeDeletedForAllUsers;
87
88
    /**
89
     * True, if the message is a channel post. All messages to channels are channel posts, all other messages are not channel posts.
90
     *
91
     * @var bool
92
     */
93
    protected bool $isChannelPost;
94
95
    /**
96
     * True, if the message contains an unread mention for the current user.
97
     *
98
     * @var bool
99
     */
100
    protected bool $containsUnreadMention;
101
102
    /**
103
     * Point in time (Unix timestamp) when the message was sent.
104
     *
105
     * @var int
106
     */
107
    protected int $date;
108
109
    /**
110
     * Point in time (Unix timestamp) when the message was last edited.
111
     *
112
     * @var int
113
     */
114
    protected int $editDate;
115
116
    /**
117
     * Information about the initial message sender; may be null.
118
     *
119
     * @var MessageForwardInfo|null
120
     */
121
    protected ?MessageForwardInfo $forwardInfo;
122
123
    /**
124
     * If non-zero, the identifier of the message this message is replying to; can be the identifier of a deleted message.
125
     *
126
     * @var int
127
     */
128
    protected int $replyToMessageId;
129
130
    /**
131
     * For self-destructing messages, the message's TTL (Time To Live), in seconds; 0 if none. TDLib will send updateDeleteMessages or updateMessageContent once the TTL expires.
132
     *
133
     * @var int
134
     */
135
    protected int $ttl;
136
137
    /**
138
     * Time left before the message expires, in seconds.
139
     *
140
     * @var float
141
     */
142
    protected float $ttlExpiresIn;
143
144
    /**
145
     * If non-zero, the user identifier of the bot through which this message was sent.
146
     *
147
     * @var int
148
     */
149
    protected int $viaBotUserId;
150
151
    /**
152
     * For channel posts, optional author signature.
153
     *
154
     * @var string
155
     */
156
    protected string $authorSignature;
157
158
    /**
159
     * Number of times this message was viewed.
160
     *
161
     * @var int
162
     */
163
    protected int $views;
164
165
    /**
166
     * Unique identifier of an album this message belongs to. Only photos and videos can be grouped together in albums.
167
     *
168
     * @var string
169
     */
170
    protected string $mediaAlbumId;
171
172
    /**
173
     * If non-empty, contains a human-readable description of the reason why access to this message must be restricted.
174
     *
175
     * @var string
176
     */
177
    protected string $restrictionReason;
178
179
    /**
180
     * Content of the message.
181
     *
182
     * @var MessageContent
183
     */
184
    protected MessageContent $content;
185
186
    /**
187
     * Reply markup for the message; may be null.
188
     *
189
     * @var ReplyMarkup|null
190
     */
191
    protected ?ReplyMarkup $replyMarkup;
192
193
    public function __construct(
194
        int $id,
195
        int $senderUserId,
196
        int $chatId,
197
        ?MessageSendingState $sendingState,
198
        ?MessageSchedulingState $schedulingState,
199
        bool $isOutgoing,
200
        bool $canBeEdited,
201
        bool $canBeForwarded,
202
        bool $canBeDeletedOnlyForSelf,
203
        bool $canBeDeletedForAllUsers,
204
        bool $isChannelPost,
205
        bool $containsUnreadMention,
206
        int $date,
207
        int $editDate,
208
        ?MessageForwardInfo $forwardInfo,
209
        int $replyToMessageId,
210
        int $ttl,
211
        float $ttlExpiresIn,
212
        int $viaBotUserId,
213
        string $authorSignature,
214
        int $views,
215
        string $mediaAlbumId,
216
        string $restrictionReason,
217
        MessageContent $content,
218
        ?ReplyMarkup $replyMarkup
219
    ) {
220
        $this->id                      = $id;
221
        $this->senderUserId            = $senderUserId;
222
        $this->chatId                  = $chatId;
223
        $this->sendingState            = $sendingState;
224
        $this->schedulingState         = $schedulingState;
225
        $this->isOutgoing              = $isOutgoing;
226
        $this->canBeEdited             = $canBeEdited;
227
        $this->canBeForwarded          = $canBeForwarded;
228
        $this->canBeDeletedOnlyForSelf = $canBeDeletedOnlyForSelf;
229
        $this->canBeDeletedForAllUsers = $canBeDeletedForAllUsers;
230
        $this->isChannelPost           = $isChannelPost;
231
        $this->containsUnreadMention   = $containsUnreadMention;
232
        $this->date                    = $date;
233
        $this->editDate                = $editDate;
234
        $this->forwardInfo             = $forwardInfo;
235
        $this->replyToMessageId        = $replyToMessageId;
236
        $this->ttl                     = $ttl;
237
        $this->ttlExpiresIn            = $ttlExpiresIn;
238
        $this->viaBotUserId            = $viaBotUserId;
239
        $this->authorSignature         = $authorSignature;
240
        $this->views                   = $views;
241
        $this->mediaAlbumId            = $mediaAlbumId;
242
        $this->restrictionReason       = $restrictionReason;
243
        $this->content                 = $content;
244
        $this->replyMarkup             = $replyMarkup;
245
    }
246
247
    public static function fromArray(array $array): Message
248
    {
249
        return new static(
250
            $array['id'],
251
            $array['sender_user_id'],
252
            $array['chat_id'],
253
            (isset($array['sending_state']) ? TdSchemaRegistry::fromArray($array['sending_state']) : null),
254
            (isset($array['scheduling_state']) ? TdSchemaRegistry::fromArray($array['scheduling_state']) : null),
255
            $array['is_outgoing'],
256
            $array['can_be_edited'],
257
            $array['can_be_forwarded'],
258
            $array['can_be_deleted_only_for_self'],
259
            $array['can_be_deleted_for_all_users'],
260
            $array['is_channel_post'],
261
            $array['contains_unread_mention'],
262
            $array['date'],
263
            $array['edit_date'],
264
            (isset($array['forward_info']) ? TdSchemaRegistry::fromArray($array['forward_info']) : null),
265
            $array['reply_to_message_id'],
266
            $array['ttl'],
267
            $array['ttl_expires_in'],
268
            $array['via_bot_user_id'],
269
            $array['author_signature'],
270
            $array['views'],
271
            $array['media_album_id'],
272
            $array['restriction_reason'],
273
            TdSchemaRegistry::fromArray($array['content']),
274
            (isset($array['reply_markup']) ? TdSchemaRegistry::fromArray($array['reply_markup']) : null),
275
        );
276
    }
277
278
    public function typeSerialize(): array
279
    {
280
        return [
281
            '@type'                        => static::TYPE_NAME,
282
            'id'                           => $this->id,
283
            'sender_user_id'               => $this->senderUserId,
284
            'chat_id'                      => $this->chatId,
285
            'sending_state'                => (isset($this->sendingState) ? $this->sendingState : null),
286
            'scheduling_state'             => (isset($this->schedulingState) ? $this->schedulingState : null),
287
            'is_outgoing'                  => $this->isOutgoing,
288
            'can_be_edited'                => $this->canBeEdited,
289
            'can_be_forwarded'             => $this->canBeForwarded,
290
            'can_be_deleted_only_for_self' => $this->canBeDeletedOnlyForSelf,
291
            'can_be_deleted_for_all_users' => $this->canBeDeletedForAllUsers,
292
            'is_channel_post'              => $this->isChannelPost,
293
            'contains_unread_mention'      => $this->containsUnreadMention,
294
            'date'                         => $this->date,
295
            'edit_date'                    => $this->editDate,
296
            'forward_info'                 => (isset($this->forwardInfo) ? $this->forwardInfo : null),
297
            'reply_to_message_id'          => $this->replyToMessageId,
298
            'ttl'                          => $this->ttl,
299
            'ttl_expires_in'               => $this->ttlExpiresIn,
300
            'via_bot_user_id'              => $this->viaBotUserId,
301
            'author_signature'             => $this->authorSignature,
302
            'views'                        => $this->views,
303
            'media_album_id'               => $this->mediaAlbumId,
304
            'restriction_reason'           => $this->restrictionReason,
305
            'content'                      => $this->content->typeSerialize(),
306
            'reply_markup'                 => (isset($this->replyMarkup) ? $this->replyMarkup : null),
307
        ];
308
    }
309
310
    public function getId(): int
311
    {
312
        return $this->id;
313
    }
314
315
    public function getSenderUserId(): int
316
    {
317
        return $this->senderUserId;
318
    }
319
320
    public function getChatId(): int
321
    {
322
        return $this->chatId;
323
    }
324
325
    public function getSendingState(): ?MessageSendingState
326
    {
327
        return $this->sendingState;
328
    }
329
330
    public function getSchedulingState(): ?MessageSchedulingState
331
    {
332
        return $this->schedulingState;
333
    }
334
335
    public function getIsOutgoing(): bool
336
    {
337
        return $this->isOutgoing;
338
    }
339
340
    public function getCanBeEdited(): bool
341
    {
342
        return $this->canBeEdited;
343
    }
344
345
    public function getCanBeForwarded(): bool
346
    {
347
        return $this->canBeForwarded;
348
    }
349
350
    public function getCanBeDeletedOnlyForSelf(): bool
351
    {
352
        return $this->canBeDeletedOnlyForSelf;
353
    }
354
355
    public function getCanBeDeletedForAllUsers(): bool
356
    {
357
        return $this->canBeDeletedForAllUsers;
358
    }
359
360
    public function getIsChannelPost(): bool
361
    {
362
        return $this->isChannelPost;
363
    }
364
365
    public function getContainsUnreadMention(): bool
366
    {
367
        return $this->containsUnreadMention;
368
    }
369
370
    public function getDate(): int
371
    {
372
        return $this->date;
373
    }
374
375
    public function getEditDate(): int
376
    {
377
        return $this->editDate;
378
    }
379
380
    public function getForwardInfo(): ?MessageForwardInfo
381
    {
382
        return $this->forwardInfo;
383
    }
384
385
    public function getReplyToMessageId(): int
386
    {
387
        return $this->replyToMessageId;
388
    }
389
390
    public function getTtl(): int
391
    {
392
        return $this->ttl;
393
    }
394
395
    public function getTtlExpiresIn(): float
396
    {
397
        return $this->ttlExpiresIn;
398
    }
399
400
    public function getViaBotUserId(): int
401
    {
402
        return $this->viaBotUserId;
403
    }
404
405
    public function getAuthorSignature(): string
406
    {
407
        return $this->authorSignature;
408
    }
409
410
    public function getViews(): int
411
    {
412
        return $this->views;
413
    }
414
415
    public function getMediaAlbumId(): string
416
    {
417
        return $this->mediaAlbumId;
418
    }
419
420
    public function getRestrictionReason(): string
421
    {
422
        return $this->restrictionReason;
423
    }
424
425
    public function getContent(): MessageContent
426
    {
427
        return $this->content;
428
    }
429
430
    public function getReplyMarkup(): ?ReplyMarkup
431
    {
432
        return $this->replyMarkup;
433
    }
434
}
435