Controller   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 23
c 0
b 0
f 0
ccs 0
cts 9
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A webhook() 0 16 3
A index() 0 3 1
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