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

InitializeKernel   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
ccs 0
cts 12
cp 0
rs 10
wmc 4
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 8 1
A resolveChannel() 0 8 2
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