EncoderPlugin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
c 3
b 1
f 0
lcom 1
cbo 4
dl 0
loc 39
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getSubscribedEvents() 0 6 1
A onAfterExecute() 0 8 2
1
<?php
2
3
namespace Crummy\Phlack\Bot\Mainframe\Plugin;
4
5
use Crummy\Phlack\Bot\Mainframe\Packet;
6
use Crummy\Phlack\Common\Events;
7
use Crummy\Phlack\Common\Formatter\EncodeFormatter;
8
use Crummy\Phlack\Common\Formatter\FormatterCollection;
9
use Crummy\Phlack\Common\Formatter\FormatterInterface;
10
use Crummy\Phlack\Common\Formatter\LinkFormatter;
11
12
class EncoderPlugin implements PluginInterface
13
{
14
    private $formatter;
15
16
    /**
17
     * @param FormatterInterface $formatter
18
     */
19 12
    public function __construct(FormatterInterface $formatter = null)
20
    {
21 12
        $this->formatter = $formatter ?: new FormatterCollection([
22 9
            new LinkFormatter(),
23 9
            new EncodeFormatter(),
24 9
        ]);
25 12
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 9
    public static function getSubscribedEvents()
31
    {
32
        return [
33 9
           Events::AFTER_EXECUTE_COMMAND => 'onAfterExecute',
34 9
       ];
35
    }
36
37
    /**
38
     * @param Packet $packet
39
     *
40
     * @return Packet
41
     */
42 2
    public function onAfterExecute(Packet $packet)
43
    {
44 2
        if (isset($packet['output'])) {
45 1
            $packet['output']['text'] = $this->formatter->format($packet['output']['text']);
46 1
        }
47
48 2
        return $packet;
49
    }
50
}
51