Controller::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation;
6
7
use FondBot\FondBot;
8
use Illuminate\Http\Request;
9
use FondBot\Contracts\WebhookVerification;
10
use Illuminate\Contracts\Events\Dispatcher;
11
12
class Controller
13
{
14
    public function index(): string
15
    {
16
        return 'FondBot v'.FondBot::VERSION;
17
    }
18
19
    public function webhook(FondBot $kernel, Dispatcher $events, Request $request)
20
    {
21
        $driver = $kernel->getChannel()->getDriver();
22
23
        // If driver supports webhook verification
24
        // We need to check if current request belongs to verification process
25
        if ($driver instanceof WebhookVerification && $driver->isVerificationRequest($request)) {
26
            return $driver->verifyWebhook($request);
27
        }
28
29
        // Resolve event from driver and dispatch it
30
        $events->dispatch(
31
            $event = $driver->createEvent($request)
32
        );
33
34
        return $driver->createResponse($request, $event);
35
    }
36
}
37