GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( ff5597...7027db )
by Stan
02:49
created

Message::setEntities()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 16
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
namespace Teebot\Entity;
4
5
use Teebot\Command\Handler;
6
use Teebot\Config;
7
8
class Message extends AbstractEntity
9
{
10
    const ENTITY_TYPE             = 'Message';
11
12
    protected $messageType = self::ENTITY_TYPE;
13
14
    protected $message_id;
15
16
    /** @var User $from */
17
    protected $from;
18
19
    protected $date;
20
21
    /** @var Chat $chat */
22
    protected $chat;
23
24
    /** @var User $forward_from */
25
    protected $forward_from;
26
27
    protected $forward_date;
28
29
    /** @var Message $reply_to_message */
30
    protected $reply_to_message;
31
32
    protected $text;
33
34
    /** @var MessageEntityArray */
35
    protected $entities;
36
37
    /** @var Audio $audio */
38
    protected $audio;
39
40
    /** @var Document $document */
41
    protected $document;
42
43
    /** @var PhotoSizeArray $photo */
44
    protected $photo;
45
46
    /** @var Sticker $sticker */
47
    protected $sticker;
48
49
    /** @var Video $video */
50
    protected $video;
51
52
    /** @var Voice $voice */
53
    protected $voice;
54
55
    protected $caption;
56
57
    /** @var Contact $contact */
58
    protected $contact;
59
60
    /** @var Location $location */
61
    protected $location;
62
63
    /** @var User $new_chat_participant */
64
    protected $new_chat_participant;
65
66
    /** @var User $left_chat_participant */
67
    protected $left_chat_participant;
68
69
    protected $new_chat_title;
70
71
    /** @var PhotoSize[] $new_chat_photo */
72
    protected $new_chat_photo;
73
74
    protected $delete_chat_photo;
75
76
    protected $group_chat_created;
77
78
    protected $supergroup_chat_created;
79
80
    protected $channel_chat_created;
81
82
    protected $migrate_to_chat_id;
83
84
    protected $migrate_from_chat_id;
85
86
    protected $pinned_message;
87
88
    protected $builtInEntities = [
89
        'from'     => User::class,
90
        'chat'     => Chat::class,
91
        'location' => Location::class,
92
        'document' => Document::class,
93
        'sticker'  => Sticker::class,
94
        'video'    => Video::class,
95
        'voice'    => Voice::class,
96
        'contact'  => Contact::class,
97
        'audio'    => Audio::class,
98
        'photo'    => PhotoSizeArray::class,
99
        'entities' => MessageEntityArray::class
100
    ];
101
102
    public function __construct(array $data)
103
    {
104
        $data = $data['message'] ?? $data;
105
106
        parent::__construct($data);
107
    }
108
109
    /**
110
     * @return null
111
     */
112
    public function getMessageId()
113
    {
114
        return $this->message_id;
115
    }
116
117
    /**
118
     * @return User
119
     */
120
    public function getFrom()
121
    {
122
        return $this->from;
123
    }
124
125
    /**
126
     * @return null
127
     */
128
    public function getChatId()
129
    {
130
        if ($this->chat instanceof Chat) {
131
            return $this->chat->getId();
132
        }
133
134
        return null;
135
    }
136
137
    /**
138
     * @return null
139
     */
140
    public function getDate()
141
    {
142
        return $this->date;
143
    }
144
145
    /**
146
     * @param mixed $text
147
     */
148
    public function setText($text)
149
    {
150
        $this->text = $text;
151
    }
152
153
    /**
154
     * @return null
155
     */
156
    public function getText()
157
    {
158
        return $this->text;
159
    }
160
161
    /**
162
     * @return array
163
     */
164
    public function getEntities()
165
    {
166
        return $this->entities;
167
    }
168
169
    /**
170
     * @param array $entities
171
     */
172
    public function setEntities($entities)
173
    {
174
        if (is_array($entities)) {
175
            $source = $this->getText();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $source is correct as $this->getText() (which targets Teebot\Entity\Message::getText()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
176
177
            $entities = array_map(function($element) use ($source) {
178
                $element['source'] = $source;
179
180
                return $element;
181
            }, $entities);
182
        }
183
        
184
185
        $this->entities = $entities;
0 ignored issues
show
Documentation Bug introduced by
It seems like $entities of type array is incompatible with the declared type object<Teebot\Entity\MessageEntityArray> of property $entities.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
186
        $this->setMessageType($entities);
187
    }
188
189
    /**
190
     * @return Chat
191
     */
192
    public function getChat()
193
    {
194
        return $this->chat;
195
    }
196
197
    /**
198
     * @return string
199
     */
200
    public function getMessageType()
201
    {
202
        return $this->messageType;
203
    }
204
205
    /**
206
     * @return Location
207
     */
208
    public function getLocation()
209
    {
210
        return $this->location;
211
    }
212
213
    /**
214
     * @param Location $location
215
     */
216
    protected function setLocation($location)
217
    {
218
        $this->location = $location;
219
        $this->setMessageType($location);
220
    }
221
222
    /**
223
     * @return Document
224
     */
225
    public function getDocument()
226
    {
227
        return $this->document;
228
    }
229
230
    /**
231
     * @param Document $document
232
     */
233
    public function setDocument($document)
234
    {
235
        $this->document = $document;
236
        $this->setMessageType($document);
237
    }
238
239
    /**
240
     * @return Sticker
241
     */
242
    public function getSticker()
243
    {
244
        return $this->sticker;
245
    }
246
247
    /**
248
     * @param Sticker $sticker
249
     */
250
    public function setSticker($sticker)
251
    {
252
        $this->sticker = $sticker;
253
        $this->setMessageType($sticker);
254
    }
255
256
    /**
257
     * @return Video
258
     */
259
    public function getVideo()
260
    {
261
        return $this->video;
262
    }
263
264
    /**
265
     * @param Video $video
266
     */
267
    public function setVideo($video)
268
    {
269
        $this->video = $video;
270
        $this->setMessageType($video);
271
    }
272
273
    /**
274
     * @return Voice
275
     */
276
    public function getVoice()
277
    {
278
        return $this->voice;
279
    }
280
281
    /**
282
     * @param Voice $voice
283
     */
284
    public function setVoice($voice)
285
    {
286
        $this->voice = $voice;
287
        $this->setMessageType($voice);
288
    }
289
290
    /**
291
     * @return Contact
292
     */
293
    public function getContact()
294
    {
295
        return $this->contact;
296
    }
297
298
    /**
299
     * @param Contact $contact
300
     */
301
    public function setContact($contact)
302
    {
303
        $this->contact = $contact;
304
        $this->setMessageType($contact);
305
    }
306
307
    /**
308
     * @return Audio
309
     */
310
    public function getAudio()
311
    {
312
        return $this->audio;
313
    }
314
315
    /**
316
     * @param Audio $audio
317
     */
318
    public function setAudio($audio)
319
    {
320
        $this->audio = $audio;
321
        $this->setMessageType($audio);
322
    }
323
324
    /**
325
     * @return PhotoSizeArray
326
     */
327
    public function getPhoto()
328
    {
329
        return $this->photo;
330
    }
331
332
    /**
333
     * @param PhotoSizeArray $photo
334
     */
335
    public function setPhoto($photo)
336
    {
337
        $this->photo = $photo;
338
        $this->setMessageType($photo);
339
    }
340
341
    protected function setMessageType($object)
342
    {
343
        $this->messageType = static::ENTITY_TYPE;
344
345
        if ($object instanceof AbstractEntity) {
346
            $this->messageType = $object->getEntityType();
347
        }
348
    }
349
350
    public function getMessageTypeEntity()
351
    {
352
        $messageTypeEntity = null;
353
354
        switch ($this->getMessageType()) {
355
            case Location::ENTITY_TYPE:
0 ignored issues
show
Coding Style introduced by
CASE statements must be defined using a colon

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
356
                $messageTypeEntity = $this->location;
357
                break;
358
            case Document::ENTITY_TYPE:
0 ignored issues
show
Coding Style introduced by
CASE statements must be defined using a colon

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
359
                $messageTypeEntity = $this->document;
360
                break;
361
            case Sticker::ENTITY_TYPE:
362
                $messageTypeEntity = $this->sticker;
363
                break;
364
            case Video::ENTITY_TYPE:
365
                $messageTypeEntity = $this->video;
366
                break;
367
            case Voice::ENTITY_TYPE:
368
                $messageTypeEntity = $this->voice;
369
                break;
370
            case Contact::ENTITY_TYPE:
371
                $messageTypeEntity = $this->contact;
372
                break;
373
            case Audio::ENTITY_TYPE:
374
                $messageTypeEntity = $this->audio;
375
                break;
376
            case PhotoSizeArray::ENTITY_TYPE:
377
                $messageTypeEntity = $this->photo;
378
                break;
379
            case MessageEntityArray::ENTITY_TYPE:
380
                $messageTypeEntity = $this->entities;
381
                break;
382
        }
383
384
        return $messageTypeEntity;
385
    }
386
}
387