Completed
Push — master ( 6a7f3a...a2dffe )
by
unknown
07:50
created

Chat::setTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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