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