Completed
Push — master ( 7de694...c3bb67 )
by Ehsan
05:18
created

Event::getApiClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Botonomous;
4
5
use Botonomous\client\ApiClient;
6
7
class Event extends AbstractBaseSlack
8
{
9
    private $type;
10
    private $user;
11
    private $text;
12
    private $timestamp;
13
    private $eventTimestamp;
14
    private $channel;
15
    private $botId;
16
17
    /**
18
     * Dependencies
19
     */
20
    private $apiClient;
21
22
    /**
23
     * Event constructor.
24
     *
25
     * @param $type
26
     */
27 13
    public function __construct($type)
28
    {
29 13
        $this->setType($type);
30 13
    }
31
32
    /**
33
     * @return string
34
     */
35 4
    public function getType()
36
    {
37 4
        return $this->type;
38
    }
39
40
    /**
41
     * @param string $type
42
     */
43 13
    public function setType($type)
44
    {
45 13
        $this->type = $type;
46 13
    }
47
48
    /**
49
     * @return string
50
     */
51 1
    public function getUser()
52
    {
53 1
        return $this->user;
54
    }
55
56
    /**
57
     * @param string $user
58
     */
59 6
    public function setUser($user)
60
    {
61 6
        $this->user = $user;
62 6
    }
63
64
    /**
65
     * @return string
66
     */
67 3
    public function getText()
68
    {
69 3
        return $this->text;
70
    }
71
72
    /**
73
     * @param string $text
74
     */
75 7
    public function setText($text)
76
    {
77 7
        $this->text = $text;
78 7
    }
79
80
    /**
81
     * @return string
82
     */
83 2
    public function getTimestamp()
84
    {
85 2
        return $this->timestamp;
86
    }
87
88
    /**
89
     * @param string $timestamp
90
     */
91 7
    public function setTimestamp($timestamp)
92
    {
93 7
        $this->timestamp = $timestamp;
94 7
    }
95
96
    /**
97
     * @return string
98
     */
99 2
    public function getEventTimestamp()
100
    {
101 2
        return $this->eventTimestamp;
102
    }
103
104
    /**
105
     * @param string $eventTimestamp
106
     */
107 7
    public function setEventTimestamp($eventTimestamp)
108
    {
109 7
        $this->eventTimestamp = $eventTimestamp;
110 7
    }
111
112
    /**
113
     * @return string
114
     */
115 4
    public function getChannel()
116
    {
117 4
        return $this->channel;
118
    }
119
120
    /**
121
     * @param string $channel
122
     */
123 7
    public function setChannel($channel)
124
    {
125 7
        $this->channel = $channel;
126 7
    }
127
128
    /**
129
     * @return string
130
     */
131 4
    public function getBotId()
132
    {
133 4
        return $this->botId;
134
    }
135
136
    /**
137
     * @param string $botId
138
     */
139 3
    public function setBotId($botId)
140
    {
141 3
        $this->botId = $botId;
142 3
    }
143
144
    /**
145
     * @return ApiClient
146
     */
147 3
    public function getApiClient()
148
    {
149 3
        if (!isset($this->apiClient)) {
150 1
            $this->setApiClient(new ApiClient());
151
        }
152
153 3
        return $this->apiClient;
154
    }
155
156
    /**
157
     * @param ApiClient $apiClient
158
     */
159 3
    public function setApiClient(ApiClient $apiClient)
160
    {
161 3
        $this->apiClient = $apiClient;
162 3
    }
163
164
    /**
165
     * Check if the event belongs to a direct message.
166
     *
167
     * @return bool|void
168
     */
169 3
    public function isDirectMessage()
170
    {
171 3
        $list = $this->getApiClient()->imList();
172
173 3
        if (empty($list)) {
174 1
            return;
175
        }
176
177 2
        foreach ($list as $imObject) {
178
            // ignore any direct conversation with the default slack bot
179 2
            if ($imObject['user'] === 'USLACKBOT') {
180 2
                continue;
181
            }
182
183
            // if IM Object id equals the event channel id the conversation is with the bot
184 2
            if ($imObject['id'] === $this->getChannel()) {
185 2
                return true;
186
            }
187
        }
188 1
    }
189
}
190