Passed
Pull Request — master (#49)
by Chubarov
02:56
created

WebhookController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A run() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Controllers;
6
7
use FondBot\Channels\ChannelManager;
8
use FondBot\Foundation\RequestHandler;
9
use Psr\Http\Message\ResponseInterface;
10
use Psr\Http\Message\ServerRequestInterface;
11
12
class WebhookController
13
{
14
    private $channelManager;
15
    private $requestHandler;
16
17 2
    public function __construct(ChannelManager $channelManager, RequestHandler $requestHandler)
18
    {
19 2
        $this->channelManager = $channelManager;
20 2
        $this->requestHandler = $requestHandler;
21 2
    }
22
23 2
    public function run(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
24
    {
25 2
        $channel = $this->channelManager->create($args['name']);
26
27 2
        $result = $this->requestHandler->handle($channel, $request);
28
29 2
        if ($result !== null) {
30 1
            $response->getBody()->write($result);
31
        }
32
33 2
        return $response->withStatus(200);
34
    }
35
}
36