Passed
Branch 1.0 (690a53)
by Vladimir
07:08
created

Controller   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 6 1
A webhook() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Application;
6
7
use FondBot\Channels\ChannelManager;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
11
class Controller
12
{
13
    protected $kernel;
14
15
    public function __construct(Kernel $kernel)
16
    {
17
        $this->kernel = $kernel;
18
    }
19
20
    public function index(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
21
    {
22
        $response->getBody()->write('FondBot v'.Kernel::VERSION);
23
24
        return $response;
25
    }
26
27
    public function webhook(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
28
    {
29
        /** @var ChannelManager $channelManager */
30
        $channelManager = $this->kernel->resolve(ChannelManager::class);
31
32
        $channel = $channelManager->create($args['name']);
33
34
        $result = $this->kernel->process($channel, $request);
35
36
        $response->getBody()->write($result);
37
38
        return $response;
39
    }
40
}
41