Completed
Push — master ( aa45ca...3f2e9d )
by Dan
01:38
created

StatusPlugin::countUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
namespace Nopolabs\Yabot\Plugin;
3
4
use Nopolabs\Yabot\Message\Message;
5
use Nopolabs\Yabot\Yabot;
6
use Psr\Log\LoggerInterface;
7
8
class StatusPlugin implements PluginInterface
9
{
10
    use PluginTrait;
11
12
    private $yabot;
13
14
    public function __construct(Yabot $yabot, LoggerInterface $logger = null)
15
    {
16
        $this->setLog($logger);
17
        $this->yabot = $yabot;
18
19
        $this->setConfig([
20
            'help' => '<prefix> status',
21
            'prefix' => PluginManager::AUTHED_USER_PREFIX,
22
            'matchers' => [
23
                'yabotStatus' => "/^status\\b/",
24
                'yabotShutdown' => "/^shutdown\\b/",
25
                'yabotReconnect' => "/^reconnect\\b/",
26
                'countUsers' => "/^count\\s+users\\b/",
27
                'countBots' => "/^count\\s+bots\\b/",
28
                'countChannels' => "/^count\\s+channels\\b/",
29
                'listUsers' => "/^list\\s+users\\b/",
30
                'listBots' => "/^list\\s+bots\\b/",
31
                'listChannels' => "/^list\\s+channels\\b/",
32
            ],
33
        ]);
34
    }
35
36
    public function yabotStatus(Message $msg)
37
    {
38
        $msg->reply($this->yabot->getStatus());
39
        $msg->setHandled(true);
40
    }
41
42
    public function yabotShutdown(Message $msg)
43
    {
44
        $this->yabot->shutDown();
45
        $msg->setHandled(true);
46
    }
47
48
    public function yabotReconnect(Message $msg)
49
    {
50
        $this->yabot->reconnect();
51
        $msg->setHandled(true);
52
    }
53
54
    public function countUsers(Message $msg)
55
    {
56
        $map = $this->yabot->getSlack()->getUsersMap();
57
58
        $msg->reply(count($map));
59
        $msg->setHandled(true);
60
    }
61
62 View Code Duplication
    public function countBots(Message $msg)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $map = $this->yabot->getSlack()->getBotsMap();
65
66
        $msg->reply(count($map));
67
        $msg->setHandled(true);
68
    }
69
70
    public function countChannels(Message $msg)
71
    {
72
        $map = $this->yabot->getSlack()->getChannelsMap();
73
74
        $msg->reply(count($map));
75
        $msg->setHandled(true);
76
    }
77
78 View Code Duplication
    public function listUsers(Message $msg)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        $map = $this->yabot->getSlack()->getUsersMap();
81
82
        $list = json_encode($map);
83
84
        $msg->reply($list);
85
        $msg->setHandled(true);
86
    }
87
88 View Code Duplication
    public function listBots(Message $msg)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        $map = $this->yabot->getSlack()->getBotsMap();
91
92
        $list = json_encode($map);
93
94
        $msg->reply($list);
95
        $msg->setHandled(true);
96
    }
97
98 View Code Duplication
    public function listChannels(Message $msg)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        $map = $this->yabot->getSlack()->getChannelsMap();
101
102
        $list = json_encode($map);
103
104
        $msg->reply($list);
105
        $msg->setHandled(true);
106
    }
107
}