Test Failed
Pull Request — master (#247)
by
unknown
09:53
created

Chat::setPermissions()   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 1
crap 2
1
<?php
2
3
namespace TelegramBot\Api\Types;
4
5
use InvalidArgumentException;
6
use TelegramBot\Api\BaseType;
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 3
     *
129
     * @var bool
130 3
     */
131
    protected $canSetStickerSet;
132
133
    /**
134
     * @return int|string
135
     */
136
    public function getId()
137
    {
138 22
        return $this->id;
139
    }
140 22
141 20
    /**
142 20
     * @param int|string $id
143 2
     *
144
     */
145 20
    public function setId($id)
146
    {
147
        if (is_integer($id) || is_float($id) || is_string($id)) {
148
            $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...
149
        } else {
150 1
            throw new InvalidArgumentException();
151
        }
152 1
    }
153
154
    /**
155
     * @return string
156
     */
157
    public function getType()
158 19
    {
159
        return $this->type;
160 19
    }
161 19
162
    /**
163
     * @param string $type
164
     */
165
    public function setType($type)
166 2
    {
167
        $this->type = $type;
168 2
    }
169
170
    /**
171
     * @return string
172
     */
173
    public function getTitle()
174 13
    {
175
        return $this->title;
176 13
    }
177 13
178
    /**
179
     * @param string $title
180
     */
181
    public function setTitle($title)
182 2
    {
183
        $this->title = $title;
184 2
    }
185
186
    /**
187
     * @return string
188
     */
189
    public function getUsername()
190 8
    {
191
        return $this->username;
192 8
    }
193 8
194
    /**
195
     * @param string $username
196
     */
197
    public function setUsername($username)
198 2
    {
199
        $this->username = $username;
200 2
    }
201
202
    /**
203
     * @return string
204
     */
205
    public function getFirstName()
206 8
    {
207
        return $this->firstName;
208 8
    }
209 8
210
    /**
211
     * @param string $firstName
212
     */
213
    public function setFirstName($firstName)
214 2
    {
215
        $this->firstName = $firstName;
216 2
    }
217
218
    /**
219
     * @return string
220
     */
221
    public function getLastName()
222 8
    {
223
        return $this->lastName;
224 8
    }
225 8
226
    /**
227
     * @param string $lastName
228
     */
229
    public function setLastName($lastName)
230 1
    {
231
        $this->lastName = $lastName;
232 1
    }
233
234
    /**
235
     * @return mixed
236
     */
237
    public function getAllMembersAreAdministrators()
238 2
    {
239
        return $this->allMembersAreAdministrators;
240 2
    }
241 2
242
    /**
243
     * @param mixed $allMembersAreAdministrators
244
     */
245
    public function setAllMembersAreAdministrators($allMembersAreAdministrators)
246 1
    {
247
        $this->allMembersAreAdministrators = $allMembersAreAdministrators;
248 1
    }
249
250
    /**
251
     * @return ChatPhoto
252
     */
253
    public function getPhoto()
254 2
    {
255
        return $this->photo;
256 2
    }
257 2
258
    /**
259
     * @param ChatPhoto $photo
260
     */
261
    public function setPhoto($photo)
262 1
    {
263
        $this->photo = $photo;
264 1
    }
265
266
    /**
267
     * @return string
268
     */
269
    public function getDescription()
270 2
    {
271
        return $this->description;
272 2
    }
273 2
274
    /**
275
     * @param string $description
276
     */
277
    public function setDescription($description)
278
    {
279
        $this->description = $description;
280
    }
281
282
    /**
283
     * @return string
284
     */
285
    public function getInviteLink()
286
    {
287
        return $this->inviteLink;
288
    }
289
290
    /**
291
     * @param string $inviteLink
292
     */
293
    public function setInviteLink($inviteLink)
294
    {
295
        $this->inviteLink = $inviteLink;
296
    }
297
298
    /**
299
     * @return Message
300
     */
301
    public function getPinnedMessage()
302
    {
303
        return $this->pinnedMessage;
304
    }
305
306
    /**
307
     * @param Message $pinnedMessage
308
     */
309
    public function setPinnedMessage($pinnedMessage)
310
    {
311
        $this->pinnedMessage = $pinnedMessage;
312
    }
313
314
    /**
315
     * @return ChatPermissions
316
     */
317
    public function getPermissions()
318
    {
319
        return $this->permissions;
320
    }
321
322
    /**
323
     * @return ChatPermissions
324
     */
325
    public function setPermissions($permissions)
326
    {
327
        $this->permissions = $permissions;
328
    }
329
330
    /**
331
     * @return string
332
     */
333
    public function getStickerSetName()
334
    {
335
        return $this->stickerSetName;
336
    }
337
338
    /**
339
     * @param string $stickerSetName
340
     */
341
    public function setStickerSetName($stickerSetName)
342
    {
343
        $this->stickerSetName = $stickerSetName;
344
    }
345
346
    /**
347
     * @return bool
348
     */
349
    public function isCanSetStickerSet()
350
    {
351
        return $this->canSetStickerSet;
352
    }
353
354
    /**
355
     * @param bool $canSetStickerSet
356
     */
357
    public function setCanSetStickerSet($canSetStickerSet)
358
    {
359
        $this->canSetStickerSet = $canSetStickerSet;
360
    }
361
}
362