MainframeKernel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 84.62%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
c 2
b 1
f 0
lcom 1
cbo 5
dl 0
loc 33
ccs 11
cts 13
cp 0.8462
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 3
A handle() 0 12 3
1
<?php
2
3
namespace Crummy\Phlack\Bridge\Symfony\HttpKernel;
4
5
use Crummy\Phlack\Bot\Mainframe\Adapter\AbstractAdapter;
6
use Crummy\Phlack\Bot\Mainframe\Mainframe;
7
use Crummy\Phlack\Bridge\Symfony\HttpFoundation\RequestConverter;
8
use Crummy\Phlack\WebHook\Reply\Reply;
9
use Crummy\Phlack\WebHook\SlashCommand;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\HttpKernel\HttpKernelInterface;
13
14
class MainframeKernel extends AbstractAdapter implements HttpKernelInterface
15
{
16
    /** @var \Crummy\Phlack\Bridge\Symfony\HttpFoundation\RequestConverter */
17
    protected $converter;
18
19
    /**
20
     * @param Mainframe        $mainframe
21
     * @param RequestConverter $converter
22
     */
23 2
    public function __construct(Mainframe $mainframe = null, RequestConverter $converter = null)
24
    {
25 2
        $mainframe = $mainframe ?: new Mainframe();
26 2
        $converter = $converter ?: new RequestConverter();
27 2
        parent::__construct($mainframe, $converter);
28 2
    }
29
30
    /**
31
     * Mediates Request handling between HttpKernelInterface and the Mainframe.
32
     * {@inheritdoc}
33
     */
34 1
    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
35
    {
36 1
        $command = $this->converter->convert($request);
37 1
        $packet = $this->mainframe->execute($command);
38 1
        $content = $packet['output'];
39
40 1
        if ($command instanceof SlashCommand && $content instanceof Reply) {
41
            $content = $content->get('text');
42
        }
43
44 1
        return new Response($content);
45
    }
46
}
47