Passed
Pull Request — master (#221)
by
unknown
02:36
created

Chat::getPermissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
        'all_members_are_administrators' => true,
31
        'photo' => ChatPhoto::class,
32
        'description' => true,
33
        'invite_link' => true,
34
        'pinned_message' => Message::class,
35
        'permissions' => ChatPermissions::class,
36
        'sticker_set_name' => true,
37
        'can_set_sticker_set' => true
38
    ];
39
40
    /**
41
     * Unique identifier for this chat, not exceeding 1e13 by absolute value
42
     *
43
     * @var int|string
44
     */
45
    protected $id;
46
47
    /**
48
     * Type of chat, can be either “private”, “group”, “supergroup” or “channel”
49
     *
50
     * @var string
51
     */
52
    protected $type;
53
54
    /**
55
     * Optional. Title, for channels and group chats
56
     *
57
     * @var string
58
     */
59
    protected $title;
60
61
    /**
62
     * Optional. Username, for private chats and channels if available
63
     *
64
     * @var string
65
     */
66
    protected $username;
67
68
    /**
69
     * Optional. First name of the other party in a private chat
70
     *
71
     * @var string
72
     */
73
    protected $firstName;
74
75
    /**
76
     * Optional. Last name of the other party in a private chat
77
     *
78
     * @var string
79
     */
80
    protected $lastName;
81
82
    protected $allMembersAreAdministrators;
83
84
    /**
85
     * Optional. Chat photo. Returned only in getChat.
86
     *
87
     * @var ChatPhoto
88
     */
89
    protected $photo;
90
91
    /**
92
     * Optional. Description, for supergroups and channel chats. Returned only in getChat.
93
     *
94
     * @var string
95
     */
96
    protected $description;
97
98
    /**
99
     * Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat.
100
     *
101
     * @var string
102
     */
103
    protected $inviteLink;
104
105
    /**
106
     * Optional. Pinned message, for supergroups. Returned only in getChat.
107
     *
108
     * @var Message
109
     */
110
    protected $pinnedMessage;
111
112
    /**
113
     * Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat.
114
     *
115
     * @var ChatPermissions
116
     */
117
    protected $permissions;
118
119
    /**
120
     * Optional. For supergroups, name of group sticker set. Returned only in getChat.
121
     *
122
     * @var string
123
     */
124
    protected $stickerSetName;
125
126
    /**
127
     * Optional. True, if the bot can change the group sticker set. Returned only in getChat.
128
     *
129
     * @var bool
130
     */
131
    protected $canSetStickerSet;
132
133
    /**
134
     * @return int|string
135
     */
136 3
    public function getId()
137
    {
138 3
        return $this->id;
139
    }
140
141
    /**
142
     * @param int|string $id
143
     *
144
     * @throws InvalidArgumentException
145
     */
146 22 View Code Duplication
    public function setId($id)
147
    {
148 22
        if (is_integer($id) || is_float($id) || is_string($id)) {
149 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...
150 20
        } else {
151 2
            throw new InvalidArgumentException();
152
        }
153 20
    }
154
155
    /**
156
     * @return string
157
     */
158 1
    public function getType()
159
    {
160 1
        return $this->type;
161
    }
162
163
    /**
164
     * @param string $type
165
     */
166 19
    public function setType($type)
167
    {
168 19
        $this->type = $type;
169 19
    }
170
171
    /**
172
     * @return string
173
     */
174 2
    public function getTitle()
175
    {
176 2
        return $this->title;
177
    }
178
179
    /**
180
     * @param string $title
181
     */
182 13
    public function setTitle($title)
183
    {
184 13
        $this->title = $title;
185 13
    }
186
187
    /**
188
     * @return string
189
     */
190 2
    public function getUsername()
191
    {
192 2
        return $this->username;
193
    }
194
195
    /**
196
     * @param string $username
197
     */
198 8
    public function setUsername($username)
199
    {
200 8
        $this->username = $username;
201 8
    }
202
203
    /**
204
     * @return string
205
     */
206 2
    public function getFirstName()
207
    {
208 2
        return $this->firstName;
209
    }
210
211
    /**
212
     * @param string $firstName
213
     */
214 8
    public function setFirstName($firstName)
215
    {
216 8
        $this->firstName = $firstName;
217 8
    }
218
219
    /**
220
     * @return string
221
     */
222 2
    public function getLastName()
223
    {
224 2
        return $this->lastName;
225
    }
226
227
    /**
228
     * @param string $lastName
229
     */
230 8
    public function setLastName($lastName)
231
    {
232 8
        $this->lastName = $lastName;
233 8
    }
234
235
    /**
236
     * @return mixed
237
     */
238 1
    public function getAllMembersAreAdministrators()
239
    {
240 1
        return $this->allMembersAreAdministrators;
241
    }
242
243
    /**
244
     * @param mixed $allMembersAreAdministrators
245
     */
246 2
    public function setAllMembersAreAdministrators($allMembersAreAdministrators)
247
    {
248 2
        $this->allMembersAreAdministrators = $allMembersAreAdministrators;
249 2
    }
250
251
    /**
252
     * @return ChatPhoto
253
     */
254 1
    public function getPhoto()
255
    {
256 1
        return $this->photo;
257
    }
258
259
    /**
260
     * @param ChatPhoto $photo
261
     */
262 2
    public function setPhoto($photo)
263
    {
264 2
        $this->photo = $photo;
265 2
    }
266
267
    /**
268
     * @return string
269
     */
270 1
    public function getDescription()
271
    {
272 1
        return $this->description;
273
    }
274
275
    /**
276
     * @param string $description
277
     */
278 2
    public function setDescription($description)
279
    {
280 2
        $this->description = $description;
281 2
    }
282
283
    /**
284
     * @return string
285
     */
286
    public function getInviteLink()
287
    {
288
        return $this->inviteLink;
289
    }
290
291
    /**
292
     * @param string $inviteLink
293
     */
294
    public function setInviteLink($inviteLink)
295
    {
296
        $this->inviteLink = $inviteLink;
297
    }
298
299
    /**
300
     * @return Message
301
     */
302
    public function getPinnedMessage()
303
    {
304
        return $this->pinnedMessage;
305
    }
306
307
    /**
308
     * @param Message $pinnedMessage
309
     */
310
    public function setPinnedMessage($pinnedMessage)
311
    {
312
        $this->pinnedMessage = $pinnedMessage;
313
    }
314
315
    /**
316
     * @return ChatPermissions
317
     */
318
    public function getPermissions()
319
    {
320
        return $this->permissions;
321
    }
322
323
    /**
324
     * @return ChatPermissions
325
     */
326
    public function setPermissions($permissions)
327
    {
328
        $this->permissions = $permissions;
329
    }
330
331
    /**
332
     * @return string
333
     */
334
    public function getStickerSetName()
335
    {
336
        return $this->stickerSetName;
337
    }
338
339
    /**
340
     * @param string $stickerSetName
341
     */
342
    public function setStickerSetName($stickerSetName)
343
    {
344
        $this->stickerSetName = $stickerSetName;
345
    }
346
347
    /**
348
     * @return bool
349
     */
350
    public function isCanSetStickerSet()
351
    {
352
        return $this->canSetStickerSet;
353
    }
354
355
    /**
356
     * @param bool $canSetStickerSet
357
     */
358
    public function setCanSetStickerSet($canSetStickerSet)
359
    {
360
        $this->canSetStickerSet = $canSetStickerSet;
361
    }
362
}
363