Passed
Push — master ( 98541d...d359a0 )
by
unknown
08:18
created

InitializeKernel::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
ccs 0
cts 4
cp 0
crap 2
rs 9.4285
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation\Middleware;
6
7
use Closure;
8
use Illuminate\Http\Request;
9
use FondBot\Channels\Channel;
10
use FondBot\Foundation\Kernel;
11
use FondBot\Channels\ChannelManager;
12
13
class InitializeKernel
14
{
15
    private $kernel;
16
    private $channelManager;
17
18
    public function __construct(Kernel $kernel, ChannelManager $channelManager)
19
    {
20
        $this->kernel = $kernel;
21
        $this->channelManager = $channelManager;
22
    }
23
24
    public function handle(Request $request, Closure $next)
25
    {
26
        $channel = $this->resolveChannel($request->route('channel'));
27
28
        $this->kernel->initialize($channel, $request);
29
30
        return $next($request);
31
    }
32
33
    private function resolveChannel($value): Channel
34
    {
35
        if (is_string($value)) {
36
            $value = $this->channelManager->get($value);
37
        }
38
39
        return $value;
40
    }
41
}
42