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

MessageEntityArray::getEntitiesByType()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.2
cc 4
eloc 8
nc 4
nop 1
1
<?php
2
3
namespace Teebot\Entity;
4
5
use Teebot\Entity\MessageEntity;
6
7
class MessageEntityArray extends AbstractEntity
8
{
9
    const ENTITY_TYPE      = 'MessageEntityArray';
10
11
    protected $entities;
12
13
    protected $supportedTypes = [
14
        MessageEntity::TYPE_BOLD,
15
        MessageEntity::TYPE_BOT_COMMAND,
16
        MessageEntity::TYPE_CODE,
17
        MessageEntity::TYPE_EMAIL,
18
        MessageEntity::TYPE_HASHTAG,
19
        MessageEntity::TYPE_ITALIC,
20
        MessageEntity::TYPE_MENTION,
21
        MessageEntity::TYPE_PRE,
22
        MessageEntity::TYPE_TEXT_LINK,
23
        MessageEntity::TYPE_URL
24
    ];
25
26
    public function __construct(array $data)
27
    {
28
        if (empty($data)) {
29
            return;
30
        }
31
32
        $this->setEntities($data);
33
34
        parent::__construct($data);
35
    }
36
37
    /**
38
     * @return mixed
39
     */
40
    public function getEntities()
41
    {
42
        return $this->entities;
43
    }
44
45
    /**
46
     * @param mixed $entities
47
     */
48
    public function setEntities(array $entities)
49
    {
50
        $this->entities = $entities;
51
52
        if (!empty($entities)) {
53
            $this->entities = [];
54
55
            $previous = null;
56
57
            foreach ($entities as $entity) {
58
                $messageEntity = new MessageEntity($entity);
59
60
                if ($previous instanceof MessageEntity) {
61
                    $previous->setNext($messageEntity);
62
                }
63
64
                $previous = $messageEntity;
65
66
                $this->entities[] = $messageEntity;
67
            }
68
        }
69
    }
70
71
    public function getEntitiesByType($type)
72
    {
73
        $entities = [];
74
75
        if (!in_array($type, $this->supportedTypes)) {
76
            return $entities;
77
        }
78
79
        foreach ($this->entities as $entity) {
80
81
            /** @var MessageEntity $entity */
82
            if ($entity->getType() === $type) {
83
                $entities[] = $entity;
84
            }
85
        }
86
87
        return $entities;
88
    }
89
}
90