Passed
Push — master ( b808b9...919917 )
by Ehsan
04:54
created

AbstractBot::getOauth()   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
31
    /**
32
     * @return Config
33
     */
34 35
    public function getConfig()
35
    {
36 35
        if ($this->config === null) {
37 31
            $this->config = (new Config());
38
        }
39
40 35
        return $this->config;
41
    }
42
43
    /**
44
     * @param Config $config
45
     */
46 9
    public function setConfig(Config $config)
47
    {
48 9
        $this->config = $config;
49 9
    }
50
51
    /**
52
     * @return AbstractBaseListener
53
     */
54 28
    public function getListener()
55
    {
56 28
        if (!isset($this->listener)) {
57 26
            $listenerClass = __NAMESPACE__.'\\listener\\'.ucwords($this->getConfig()->get('listenerType')).'Listener';
58 26
            $this->setListener(new $listenerClass());
59
        }
60
61 28
        return $this->listener;
62
    }
63
64 28
    public function setListener(AbstractBaseListener $listener)
65
    {
66 28
        $this->listener = $listener;
67 28
    }
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 1
    public function getFormattingUtility()
113
    {
114 1
        if (!isset($this->formattingUtility)) {
115 1
            $this->setFormattingUtility(new FormattingUtility());
116
        }
117
118 1
        return $this->formattingUtility;
119
    }
120
121
    /**
122
     * @param FormattingUtility $formattingUtility
123
     */
124 1
    public function setFormattingUtility(FormattingUtility $formattingUtility)
125
    {
126 1
        $this->formattingUtility = $formattingUtility;
127 1
    }
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 7
    public function getRequestUtility()
173
    {
174 7
        if (!isset($this->requestUtility)) {
175 4
            $this->setRequestUtility((new RequestUtility()));
176
        }
177
178 7
        return $this->requestUtility;
179
    }
180
181
    /**
182
     * @param RequestUtility $requestUtility
183
     */
184 7
    public function setRequestUtility(RequestUtility $requestUtility)
185
    {
186 7
        $this->requestUtility = $requestUtility;
187 7
    }
188
189
    /**
190
     * @return BlackList
191
     */
192 2
    public function getBlackList()
193
    {
194 2
        if (!isset($this->blackList)) {
195 1
            $this->setBlackList(new BlackList($this->getListener()->getRequest()));
196
        }
197
198 2
        return $this->blackList;
199
    }
200
201
    /**
202
     * @param BlackList $blackList
203
     */
204 2
    public function setBlackList(BlackList $blackList)
205
    {
206 2
        $this->blackList = $blackList;
207 2
    }
208
209
    /**
210
     * @return WhiteList
211
     */
212 1
    public function getWhiteList()
213
    {
214 1
        if (!isset($this->whiteList)) {
215 1
            $this->setWhiteList(new WhiteList($this->getListener()->getRequest()));
216
        }
217
218 1
        return $this->whiteList;
219
    }
220
221
    /**
222
     * @param WhiteList $whiteList
223
     */
224 1
    public function setWhiteList(WhiteList $whiteList)
225
    {
226 1
        $this->whiteList = $whiteList;
227 1
    }
228
229
    /**
230
     * @return Sender
231
     */
232 5
    public function getSender()
233
    {
234 5
        if (!isset($this->sender)) {
235 5
            $this->setSender(new Sender($this));
236
        }
237
238 5
        return $this->sender;
239
    }
240
241
    /**
242
     * @param Sender $sender
243
     */
244 5
    public function setSender(Sender $sender)
245
    {
246 5
        $this->sender = $sender;
247 5
    }
248
}
249