Completed
Push — master ( 4c7365...be3bdc )
by Vladimir
02:21
created

Controller::webhook()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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