Completed
Push — master ( 21c774...ed97c6 )
by Vladimir
49:18 queued 09:54
created

Controller   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

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

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\Http\Request;
8
use FondBot\Channels\ChannelManager;
9
use Psr\Http\Message\RequestInterface;
10
use Psr\Http\Message\ResponseInterface;
11
12
class Controller
13
{
14
    protected $kernel;
15
16 4
    public function __construct(Kernel $kernel)
17
    {
18 4
        $this->kernel = $kernel;
19 4
    }
20
21 1
    public function index(RequestInterface $request, ResponseInterface $response): ResponseInterface
22
    {
23 1
        $response->getBody()->write('FondBot v'.Kernel::VERSION);
24
25 1
        return $response;
26
    }
27
28 1
    public function webhook(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
29
    {
30
        /** @var ChannelManager $channelManager */
31 1
        $channelManager = $this->kernel->resolve(ChannelManager::class);
32
33 1
        $channel = $channelManager->create($args['name']);
34
35 1
        $result = $this->kernel->process($channel, Request::fromMessage($request));
36
37 1
        $response->getBody()->write($result);
38
39 1
        return $response;
40
    }
41
}
42