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

WebhookController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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