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 ( 5ac723...c719eb )
by Stan
07:02
created

AbstractEntityEvent   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 119
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
run() 0 1 ?
A setParams() 0 6 1
A getChatId() 0 14 3
A setProcessor() 0 6 1
A setEntity() 0 6 1
A sendMessage() 0 7 1
A reply() 0 11 2
1
<?php
2
3
/**
4
 * Abstract entity event class is base class for creating the events for received in response entities. It
5
 * includes methods to be able to quickly get a chat id and reply on message, get parent entity which
6
 * triggered this entity event.
7
 *
8
 * @package Teebot (Telegram bot framework)
9
 *
10
 * @author  Stanislav Drozdov <[email protected]>
11
 */
12
13
namespace Teebot\Api\Command;
14
15
use Teebot\Api\Entity\EntityInterface;
16
use Teebot\Api\Method\SendMessage;
17
use Teebot\Api\Entity\Message;
18
19
abstract class AbstractEntityEvent implements EventInterface
20
{
21
    /**
22
     * @var Processor $processor
23
     */
24
    protected $processor;
25
26
    /**
27
     * @var array
28
     */
29
    protected $params;
30
31
    /**
32
     * @var EntityInterface $entity
33
     */
34
    protected $entity = null;
35
36
    /**
37
     * Abstract method of each entity event which will be called if certain entity presents in response
38
     * and it's class exists or mapped in the config. 
39
     * 
40
     * @return null|bool
41
     */
42
    abstract public function run();
43
44
    /**
45
     * Sets configuration parameters
46
     *
47
     * @param array $params
48
     *
49
     * @return $this
50
     */
51
    public function setParams(array $params)
52
    {
53
        $this->params = $params;
54
55
        return $this;
56
    }
57
58
    /**
59
     * Returns chat id if the type of calling entity or it's parent is Message
60
     *
61
     * @return null|int
62
     */
63
    public function getChatId()
64
    {
65
        if ($this->entity instanceof Message) {
66
            return $this->entity->getChatId();
67
        }
68
69
        $parent = $this->entity->getParent();
70
71
        if ($parent instanceof Message) {
72
            return $parent->getChatId();
73
        }
74
75
        return null;
76
    }
77
78
    /**
79
     * @param Processor $processor
80
     *
81
     * @return $this
82
     */
83
    public function setProcessor(Processor $processor)
84
    {
85
        $this->processor = $processor;
86
87
        return $this;
88
    }
89
90
    /**
91
     * Sets entity
92
     *
93
     * @param EntityInterface $entity Entity object
94
     *
95
     * @return $this
96
     */
97
    public function setEntity(EntityInterface $entity)
98
    {
99
        $this->entity = $entity;
100
101
        return $this;
102
    }
103
104
    /**
105
     * Sends text message to current chat
106
     *
107
     * @param string $text Message text
108
     *
109
     * @return bool|\Teebot\Api\Response
110
     */
111
    protected function sendMessage($text)
112
    {
113
        return $this->reply(
114
            (new SendMessage())
115
                ->setText($text)
116
        );
117
    }
118
119
    /**
120
     * Replies on the message
121
     *
122
     * @param SendMessage $sendMessage Object of the SendMessage method
123
     *
124
     * @return bool|\Teebot\Api\Response
125
     */
126
    protected function reply(SendMessage $sendMessage) {
127
        $chatId = $this->getChatId();
128
129
        if ((int) $chatId == 0) {
130
            return false;
131
        }
132
133
        $sendMessage->setChatId($chatId);
134
135
        return $this->processor->call($sendMessage, true, $this->entity);
136
    }
137
}
138