Hey::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 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
}