Passed
Push — master ( 2fea8c...bfe50b )
by Ehsan
03:00
created

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