Completed
Push — master ( 1b605f...95b7c3 )
by Dan
06:00
created

MessageLogPlugin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 43
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A status() 0 8 2
A start() 0 5 1
A stop() 0 5 1
1
<?php
2
3
namespace Nopolabs\Yabot\Plugin;
4
5
6
use Nopolabs\Yabot\Message\Message;
7
use Nopolabs\Yabot\Yabot;
8
use Psr\Log\LoggerInterface;
9
10
class MessageLogPlugin implements PluginInterface
11
{
12
    use PluginTrait;
13
14
    private $yabot;
15
16
    public function __construct(LoggerInterface $logger, Yabot $yabot)
17
    {
18
        $this->setLog($logger);
19
        $this->yabot = $yabot;
20
21
        $this->setConfig([
22
            'help' => "<prefix> start\n<prefix> stop\n",
23
            'prefix' => 'messagelog',
24
            'messageLogFile' => 'message.log',
25
            'matchers' => [
26
                'start' => "/^start\\b/",
27
                'stop' => "/^stop\\b/",
28
            ],
29
        ]);
30
    }
31
32
    public function status(): string
33
    {
34
        if ($file = $this->yabot->getMessageLog()) {
35
            return "logging messages in $file";
36
        }
37
38
        return 'not logging messages';
39
    }
40
41
    public function start(Message $msg, array $matches)
1 ignored issue
show
Unused Code introduced by
The parameter $matches is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
        $this->yabot->setMessageLog($this->get('messageLogFile'));
44
        $msg->setHandled(true);
45
    }
46
47
    public function stop(Message $msg, array $matches)
1 ignored issue
show
Unused Code introduced by
The parameter $matches is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        $this->yabot->setMessageLog(null);
50
        $msg->setHandled(true);
51
    }
52
}