Test Failed
Pull Request — master (#306)
by Eldar
02:36
created

Chat::setDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace TelegramBot\Api\Types;
4
5
use TelegramBot\Api\BaseType;
6
use TelegramBot\Api\InvalidArgumentException;
7
use TelegramBot\Api\TypeInterface;
8
9
class Chat extends BaseType implements TypeInterface
10
{
11
    /**
12
     * {@inheritdoc}
13
     *
14
     * @var array
15
     */
16
    static protected $requiredParams = ['id', 'type'];
17
18
    /**
19
     * {@inheritdoc}
20
     *
21
     * @var array
22
     */
23
    static protected $map = [
24
        'id' => true,
25
        'type' => true,
26
        'title' => true,
27
        'username' => true,
28
        'first_name' => true,
29
        'last_name' => true,
30
        'photo' => ChatPhoto::class,
31
        'bio' => true,
32
        'description' => true,
33
        'invite_link' => true,
34
        'pinned_message' => Message::class,
35
        'permissions' => ChatPermissions::class,
36
        'slow_mode_delay' => true,
37
        'sticker_set_name' => true,
38
        'can_set_sticker_set' => true,
39
        'linked_chat_id' => true,
40
        'location' => ChatLocation::class
41
    ];
42
43
    /**
44
     * Unique identifier for this chat, not exceeding 1e13 by absolute value
45
     *
46
     * @var int|string
47
     */
48
    protected $id;
49
50
    /**
51
     * Type of chat, can be either “private”, “group”, “supergroup” or “channel”
52
     *
53
     * @var string
54
     */
55
    protected $type;
56
57
    /**
58
     * Optional. Title, for channels and group chats
59
     *
60
     * @var string
61
     */
62
    protected $title;
63
64
    /**
65
     * Optional. Username, for private chats and channels if available
66
     *
67
     * @var string
68
     */
69
    protected $username;
70
71
    /**
72
     * Optional. First name of the other party in a private chat
73
     *
74
     * @var string
75
     */
76
    protected $firstName;
77
78
    /**
79
     * Optional. Last name of the other party in a private chat
80
     *
81
     * @var string
82
     */
83
    protected $lastName;
84
85
    /**
86
     * Optional. Chat photo. Returned only in getChat.
87
     *
88
     * @var ChatPhoto
89
     */
90
    protected $photo;
91
92
    /**
93
     * Optional. Bio of the other party in a private chat. Returned only in getChat
94
     *
95
     * @var string
96
     */
97
    protected $bio;
98
99
    /**
100
     * Optional. Description, for supergroups and channel chats. Returned only in getChat.
101
     *
102
     * @var string
103
     */
104
    protected $description;
105
106
    /**
107
     * Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat.
108
     *
109
     * @var string
110
     */
111
    protected $inviteLink;
112
113
    /**
114
     * Optional. Pinned message, for supergroups. Returned only in getChat.
115
     *
116
     * @var Message
117
     */
118
    protected $pinnedMessage;
119
120
    /**
121
     * Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat.
122
     *
123
     * @var ChatPermissions
124
     */
125
    protected $permissions;
126
127
    /**
128
     * Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged
129
     * user. Returned only in getChat.
130
     *
131
     * @var int
132
     */
133
    protected $slowModeDelay;
134
135
    /**
136
     * Optional. For supergroups, name of group sticker set. Returned only in getChat.
137
     *
138
     * @var string
139
     */
140
    protected $stickerSetName;
141
142
    /**
143
     * Optional. True, if the bot can change the group sticker set. Returned only in getChat.
144
     *
145
     * @var bool
146
     */
147
    protected $canSetStickerSet;
148
149
    /**
150
     * Optional. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice
151
     * versa; for supergroups and channel chats. This identifier may be greater than 32 bits and some programming
152
     * languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64
153
     * bit integer or double-precision float type are safe for storing this identifier. Returned only in getChat.
154
     *
155
     * @var int
156
     */
157
    protected $linkedChatId;
158
159
    /**
160
     * Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat.
161
     *
162
     * @var ChatLocation
163
     */
164
    protected $location;
165
166
    /**
167
     * @return int|string
168
     */
169 3
    public function getId()
170
    {
171 3
        return $this->id;
172
    }
173
174
    /**
175
     * @param int|string $id
176
     *
177
     * @throws InvalidArgumentException
178
     */
179 22 View Code Duplication
    public function setId($id)
180
    {
181 22
        if (is_integer($id) || is_float($id) || is_string($id)) {
182 20
            $this->id = $id;
0 ignored issues
show
Documentation Bug introduced by
It seems like $id can also be of type double. However, the property $id is declared as type integer|string. 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...
183 20
        } else {
184 2
            throw new InvalidArgumentException();
185
        }
186 20
    }
187
188
    /**
189
     * @return string
190
     */
191 1
    public function getType()
192
    {
193 1
        return $this->type;
194
    }
195
196
    /**
197
     * @param string $type
198
     */
199 19
    public function setType($type)
200
    {
201 19
        $this->type = $type;
202 19
    }
203
204
    /**
205
     * @return string
206
     */
207 2
    public function getTitle()
208
    {
209 2
        return $this->title;
210
    }
211
212
    /**
213
     * @param string $title
214
     */
215 13
    public function setTitle($title)
216
    {
217 13
        $this->title = $title;
218 13
    }
219
220
    /**
221
     * @return string
222
     */
223 2
    public function getUsername()
224
    {
225 2
        return $this->username;
226
    }
227
228
    /**
229
     * @param string $username
230
     */
231 8
    public function setUsername($username)
232
    {
233 8
        $this->username = $username;
234 8
    }
235
236
    /**
237
     * @return string
238
     */
239 2
    public function getFirstName()
240
    {
241 2
        return $this->firstName;
242
    }
243
244
    /**
245
     * @param string $firstName
246
     */
247 8
    public function setFirstName($firstName)
248
    {
249 8
        $this->firstName = $firstName;
250 8
    }
251
252
    /**
253
     * @return string
254
     */
255 2
    public function getLastName()
256
    {
257 2
        return $this->lastName;
258
    }
259
260
    /**
261
     * @param string $lastName
262
     */
263 8
    public function setLastName($lastName)
264
    {
265 8
        $this->lastName = $lastName;
266 8
    }
267
268
    /**
269
     * @return ChatPhoto
270
     */
271 1
    public function getPhoto()
272
    {
273 1
        return $this->photo;
274
    }
275
276
    /**
277
     * @param ChatPhoto $photo
278
     */
279 2
    public function setPhoto($photo)
280
    {
281 2
        $this->photo = $photo;
282 2
    }
283
284
    /**
285
     * @return string
286
     */
287 2
    public function getBio()
288
    {
289 2
        return $this->bio;
290
    }
291
292
    /**
293
     * @param string $bio
294
     */
295 3
    public function setBio($bio)
296
    {
297 3
        $this->bio = $bio;
298 3
    }
299
300
    /**
301
     * @return string
302
     */
303 1
    public function getDescription()
304
    {
305 1
        return $this->description;
306
    }
307
308
    /**
309
     * @param string $description
310
     */
311 2
    public function setDescription($description)
312
    {
313 2
        $this->description = $description;
314 2
    }
315
316
    /**
317
     * @return string
318
     */
319
    public function getInviteLink()
320
    {
321
        return $this->inviteLink;
322
    }
323
324
    /**
325
     * @param string $inviteLink
326
     */
327
    public function setInviteLink($inviteLink)
328
    {
329
        $this->inviteLink = $inviteLink;
330
    }
331
332
    /**
333
     * @return Message
334
     */
335
    public function getPinnedMessage()
336
    {
337
        return $this->pinnedMessage;
338
    }
339
340
    /**
341
     * @param Message $pinnedMessage
342
     */
343
    public function setPinnedMessage($pinnedMessage)
344
    {
345
        $this->pinnedMessage = $pinnedMessage;
346
    }
347
348
    /**
349
     * @return ChatPermissions
350
     */
351
    public function getPermissions()
352
    {
353
        return $this->permissions;
354
    }
355
356
    /**
357
     * @param ChatPermissions $permissions
358
     */
359
    public function setPermissions($permissions)
360
    {
361
        $this->permissions = $permissions;
362
    }
363
364
    /**
365
     * @return int
366
     */
367
    public function getSlowModeDelay()
368
    {
369
        return $this->slowModeDelay;
370
    }
371
372
    /**
373
     * @param int $slowModeDelay
374
     */
375
    public function setSlowModeDelay($slowModeDelay)
376
    {
377
        $this->slowModeDelay = $slowModeDelay;
378
    }
379
380
    /**
381
     * @return string
382
     */
383
    public function getStickerSetName()
384
    {
385
        return $this->stickerSetName;
386
    }
387
388
    /**
389
     * @param string $stickerSetName
390
     */
391
    public function setStickerSetName($stickerSetName)
392
    {
393
        $this->stickerSetName = $stickerSetName;
394
    }
395
396
    /**
397
     * @return bool
398
     */
399
    public function isCanSetStickerSet()
400
    {
401
        return $this->canSetStickerSet;
402
    }
403
404
    /**
405
     * @param bool $canSetStickerSet
406
     */
407
    public function setCanSetStickerSet($canSetStickerSet)
408
    {
409
        $this->canSetStickerSet = $canSetStickerSet;
410
    }
411
412
    /**
413
     * @return int
414
     */
415
    public function getLinkedChatId()
416
    {
417
        return $this->linkedChatId;
418
    }
419
420
    /**
421
     * @param int $linkedChatId
422
     */
423
    public function setLinkedChatId($linkedChatId)
424
    {
425
        $this->linkedChatId = $linkedChatId;
426
    }
427
428
    /**
429
     * @return ChatLocation
430
     */
431
    public function getLocation()
432
    {
433
        return $this->location;
434
    }
435
436
    /**
437
     * @param ChatLocation $location
438
     */
439
    public function setLocation($location)
440
    {
441
        $this->location = $location;
442
    }
443
}
444