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 ( 617fa5...872112 )
by Stan
06:31
created

MessageEntityArray   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 11

4 Methods

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