Hey   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A hey() 0 5 1
A thread() 0 6 1
1
<?php
2
3
namespace Nopolabs\Yabot\Plugins\Examples;
4
5
use Nopolabs\Yabot\Message\Message;
6
use Nopolabs\Yabot\Plugin\PluginInterface;
7
use Nopolabs\Yabot\Plugin\PluginTrait;
8
use Psr\Log\LoggerInterface;
9
10
class Hey implements PluginInterface
11
{
12
    use PluginTrait;
13
14
    public function __construct(LoggerInterface $logger)
15
    {
16
        $this->setLog($logger);
17
18
        $this->setConfig([
19
            'prefix' => 'hey',
20
            'matchers' => [
21
                'hey-thread' => [
22
                    'patterns' => ["/^thread\\s+(?'text'[^?].*)/"],
23
                    'method' => 'thread',
24
                ],
25
                'hey' => [
26
                    'patterns' => ["/^(?'text'[^?].*)/"],
27
                ],
28
            ],
29
        ]);
30
    }
31
32
    public function hey(Message $msg, array $matches)
33
    {
34
        $msg->reply('hey => '.$matches['text']);
35
        $msg->setHandled(true);
36
    }
37
38
    public function thread(Message $msg, array $matches)
39
    {
40
        $attachments = ['attachments' => json_encode([["text" => $matches['text']]])];
41
        $msg->thread('thread', $attachments);
42
        $msg->setHandled(true);
43
    }
44
}