Passed
Push — master ( ff83e3...5f4a5c )
by Ehsan
03:54
created

AbstractBot   C

Complexity

Total Complexity 35

Size/Duplication

Total Lines 251
Duplicated Lines 0 %

Coupling/Cohesion

Components 8
Dependencies 11

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 35
lcom 8
cbo 11
dl 0
loc 251
ccs 83
cts 83
cp 1
rs 6.923
c 0
b 0
f 0

24 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 8 2
A setConfig() 0 4 1
A getListener() 0 9 2
A setListener() 0 4 1
A getMessageUtility() 0 8 2
A setMessageUtility() 0 4 1
A getCommandContainer() 0 8 2
A setCommandContainer() 0 4 1
A getFormattingUtility() 0 8 2
A setFormattingUtility() 0 4 1
A getLoggerUtility() 0 8 2
A setLoggerUtility() 0 4 1
A getOauth() 0 8 2
A setOauth() 0 4 1
A getRequestUtility() 0 4 1
A setRequestUtility() 0 4 1
A getBlackList() 0 8 2
A setBlackList() 0 4 1
A getWhiteList() 0 8 2
A setWhiteList() 0 4 1
A getSender() 0 8 2
A setSender() 0 4 1
A getDictionary() 0 8 2
A setDictionary() 0 4 1
1
<?php
2
3
namespace Botonomous;
4
5
use Botonomous\listener\AbstractBaseListener;
6
use Botonomous\utility\FormattingUtility;
7
use Botonomous\utility\LoggerUtility;
8
use Botonomous\utility\MessageUtility;
9
use Botonomous\utility\RequestUtility;
10
11
/**
12
 * Class AbstractBot.
13
 */
14
abstract class AbstractBot
15
{
16
    /**
17
     * Dependencies.
18
     */
19
    protected $config;
20
    protected $listener;
21
    protected $messageUtility;
22
    protected $commandContainer;
23
    protected $formattingUtility;
24
    protected $loggerUtility;
25
    protected $oauth;
26
    protected $blackList;
27
    protected $whiteList;
28
    protected $sender;
29
    protected $dictionary;
30
31
    /**
32
     * @return Config
33
     */
34 42
    public function getConfig()
35
    {
36 42
        if ($this->config === null) {
37 36
            $this->config = (new Config());
38
        }
39
40 42
        return $this->config;
41
    }
42
43
    /**
44
     * @param Config $config
45
     */
46 11
    public function setConfig(Config $config)
47
    {
48 11
        $this->config = $config;
49 11
    }
50
51
    /**
52
     * @return AbstractBaseListener
53
     */
54 33
    public function getListener()
55
    {
56 33
        if (!isset($this->listener)) {
57 31
            $listenerClass = __NAMESPACE__.'\\listener\\'.ucwords($this->getConfig()->get('listener')).'Listener';
58 31
            $this->setListener(new $listenerClass());
59
        }
60
61 33
        return $this->listener;
62
    }
63
64 33
    public function setListener(AbstractBaseListener $listener)
65
    {
66 33
        $this->listener = $listener;
67 33
    }
68
69
    /**
70
     * @return MessageUtility
71
     */
72 9
    public function getMessageUtility()
73
    {
74 9
        if (!isset($this->messageUtility)) {
75 9
            $this->setMessageUtility(new MessageUtility());
76
        }
77
78 9
        return $this->messageUtility;
79
    }
80
81
    /**
82
     * @param MessageUtility $messageUtility
83
     */
84 9
    public function setMessageUtility(MessageUtility $messageUtility)
85
    {
86 9
        $this->messageUtility = $messageUtility;
87 9
    }
88
89
    /**
90
     * @return CommandContainer
91
     */
92 5
    public function getCommandContainer()
93
    {
94 5
        if (!isset($this->commandContainer)) {
95 5
            $this->setCommandContainer(new CommandContainer());
96
        }
97
98 5
        return $this->commandContainer;
99
    }
100
101
    /**
102
     * @param CommandContainer $commandContainer
103
     */
104 5
    public function setCommandContainer(CommandContainer $commandContainer)
105
    {
106 5
        $this->commandContainer = $commandContainer;
107 5
    }
108
109
    /**
110
     * @return FormattingUtility
111
     */
112 2
    public function getFormattingUtility()
113
    {
114 2
        if (!isset($this->formattingUtility)) {
115 1
            $this->setFormattingUtility(new FormattingUtility());
116
        }
117
118 2
        return $this->formattingUtility;
119
    }
120
121
    /**
122
     * @param FormattingUtility $formattingUtility
123
     */
124 2
    public function setFormattingUtility(FormattingUtility $formattingUtility)
125
    {
126 2
        $this->formattingUtility = $formattingUtility;
127 2
    }
128
129
    /**
130
     * @return LoggerUtility
131
     */
132 1
    public function getLoggerUtility()
133
    {
134 1
        if (!isset($this->loggerUtility)) {
135 1
            $this->setLoggerUtility(new LoggerUtility());
136
        }
137
138 1
        return $this->loggerUtility;
139
    }
140
141
    /**
142
     * @param LoggerUtility $loggerUtility
143
     */
144 1
    public function setLoggerUtility(LoggerUtility $loggerUtility)
145
    {
146 1
        $this->loggerUtility = $loggerUtility;
147 1
    }
148
149
    /**
150
     * @return OAuth
151
     */
152 2
    public function getOauth()
153
    {
154 2
        if (!isset($this->oauth)) {
155 1
            $this->setOauth(new OAuth());
156
        }
157
158 2
        return $this->oauth;
159
    }
160
161
    /**
162
     * @param OAuth $oauth
163
     */
164 2
    public function setOauth(OAuth $oauth)
165
    {
166 2
        $this->oauth = $oauth;
167 2
    }
168
169
    /**
170
     * @return RequestUtility
171
     */
172 2
    public function getRequestUtility()
173
    {
174 2
        return $this->getListener()->getRequestUtility();
175
    }
176
177
    /**
178
     * @param RequestUtility $requestUtility
179
     */
180 3
    public function setRequestUtility(RequestUtility $requestUtility)
181
    {
182 3
        $this->getListener()->setRequestUtility($requestUtility);
183 3
    }
184
185
    /**
186
     * @return BlackList
187
     */
188 2
    public function getBlackList()
189
    {
190 2
        if (!isset($this->blackList)) {
191 1
            $this->setBlackList(new BlackList($this->getListener()->getRequest()));
192
        }
193
194 2
        return $this->blackList;
195
    }
196
197
    /**
198
     * @param BlackList $blackList
199
     */
200 2
    public function setBlackList(BlackList $blackList)
201
    {
202 2
        $this->blackList = $blackList;
203 2
    }
204
205
    /**
206
     * @return WhiteList
207
     */
208 1
    public function getWhiteList()
209
    {
210 1
        if (!isset($this->whiteList)) {
211 1
            $this->setWhiteList(new WhiteList($this->getListener()->getRequest()));
212
        }
213
214 1
        return $this->whiteList;
215
    }
216
217
    /**
218
     * @param WhiteList $whiteList
219
     */
220 1
    public function setWhiteList(WhiteList $whiteList)
221
    {
222 1
        $this->whiteList = $whiteList;
223 1
    }
224
225
    /**
226
     * @return Sender
227
     */
228 4
    public function getSender()
229
    {
230 4
        if (!isset($this->sender)) {
231 4
            $this->setSender(new Sender($this));
232
        }
233
234 4
        return $this->sender;
235
    }
236
237
    /**
238
     * @param Sender $sender
239
     */
240 4
    public function setSender(Sender $sender)
241
    {
242 4
        $this->sender = $sender;
243 4
    }
244
245
    /**
246
     * @return Dictionary
247
     */
248 6
    public function getDictionary()
249
    {
250 6
        if (!isset($this->dictionary)) {
251 6
            $this->setDictionary(new Dictionary());
252
        }
253
254 6
        return $this->dictionary;
255
    }
256
257
    /**
258
     * @param Dictionary $dictionary
259
     */
260 6
    public function setDictionary(Dictionary $dictionary)
261
    {
262 6
        $this->dictionary = $dictionary;
263 6
    }
264
}
265