File tree Expand file tree Collapse file tree 7 files changed +39
-7
lines changed
Expand file tree Collapse file tree 7 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ public function get($key)
1919 $ commands = $ this ->getAll ($ key );
2020
2121 if (!array_key_exists ($ key , $ commands )) {
22+ /** @noinspection PhpInconsistentReturnPointsInspection */
2223 return ;
2324 }
2425
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ class Slackbot
1515{
1616 private $ request ;
1717 private $ config ;
18+ private $ commands ;
1819
1920 /**
2021 * Slackbot constructor.
@@ -57,10 +58,9 @@ public function setRequest($request)
5758 /**
5859 * @param null $key
5960 *
60- * @throws \Exception
61- *
6261 * @return mixed
6362 */
63+ /** @noinspection PhpInconsistentReturnPointsInspection */
6464 public function getRequest ($ key = null )
6565 {
6666 if ($ key === null ) {
@@ -268,4 +268,24 @@ public function setConfig(Config $config)
268268 {
269269 $ this ->config = $ config ;
270270 }
271+
272+ /**
273+ * @return array
274+ */
275+ public function getCommands ()
276+ {
277+ if (!isset ($ this ->commands )) {
278+ $ this ->setCommands ((new CommandContainer ())->getAll ());
279+ }
280+
281+ return $ this ->commands ;
282+ }
283+
284+ /**
285+ * @param array $commands
286+ */
287+ public function setCommands (array $ commands )
288+ {
289+ $ this ->commands = $ commands ;
290+ }
271291}
Original file line number Diff line number Diff line change 33namespace Slackbot \plugin \help ;
44
55use Slackbot \Command ;
6- use Slackbot \CommandContainer ;
76use Slackbot \plugin \AbstractPlugin ;
87use Slackbot \utility \FormattingUtility ;
98
@@ -17,7 +16,7 @@ class Help extends AbstractPlugin
1716 */
1817 public function index ()
1918 {
20- $ allCommands = ( new CommandContainer ())-> getAll ();
19+ $ allCommands = $ this -> getSlackbot ()-> getCommands ();
2120
2221 $ response = '' ;
2322 if (!empty ($ allCommands )) {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ public function testGet()
2121
2222 $ this ->assertTrue ($ commandObject instanceof Command);
2323
24+ /** @noinspection PhpUndefinedMethodInspection */
2425 $ this ->assertEquals ($ commandObject ->getPlugin (), 'Ping ' );
2526 }
2627
@@ -30,6 +31,7 @@ public function testGet()
3031 public function testGetAll ()
3132 {
3233 $ commands = (new CommandContainer ())->getAll ();
34+ /** @noinspection PhpUndefinedMethodInspection */
3335 $ this ->assertEquals ($ commands ['ping ' ]->getPlugin (), 'Ping ' );
3436 }
3537}
Original file line number Diff line number Diff line change 22
33namespace Slackbot ;
44
5+ /** @noinspection PhpUndefinedClassInspection */
56class CommandTest extends \PHPUnit_Framework_TestCase
67{
8+ const PING_KEY = 'ping ' ;
9+
710 public function testGetAction ()
811 {
9- $ command = new Command (' ping ' );
12+ $ command = new Command (self :: PING_KEY );
1013
1114 $ this ->assertEquals (Command::DEFAULT_ACTION , $ command ->getAction ());
1215 }
16+
17+ public function testGetKey ()
18+ {
19+ $ command = new Command (self ::PING_KEY );
20+
21+ $ this ->assertEquals (self ::PING_KEY , $ command ->getKey ());
22+ }
1323}
Original file line number Diff line number Diff line change 88 * Class ConfigTest.
99 */
1010
11- /** @noinspection PhpUndefinedClassInspection */
12-
1311/** @noinspection PhpUndefinedClassInspection */
1412class ConfigTest extends \PHPUnit_Framework_TestCase
1513{
Original file line number Diff line number Diff line change @@ -209,13 +209,15 @@ private function outputOnNoCommand($message)
209209
210210 if (!empty ($ defaultCommand )) {
211211 $ commandObject = (new CommandContainer ())->get ($ defaultCommand );
212+ /** @noinspection PhpUndefinedMethodInspection */
212213 $ commandClass = $ commandObject ->getClass ();
213214
214215 /**
215216 * @var AbstractPlugin
216217 */
217218 $ pluginObject = (new $ commandClass ($ slackbot ));
218219
220+ /** @noinspection PhpUndefinedMethodInspection */
219221 return $ pluginObject ->index ();
220222 }
221223
You can’t perform that action at this time.
0 commit comments