Completed
Push — develop ( 059b46...8f56e3 )
by Michele
02:21
created

BaseWebhook::resolveTokenFromPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zanzara\UpdateMode;
6
7
/**
8
 *
9
 */
10
abstract class BaseWebhook extends UpdateMode
11
{
12
13
    /**
14
     * @param string|null $token
15
     * @return bool
16
     */
17
    protected function isWebhookAuthorized(?string $token = null): bool
18
    {
19
        if (!$this->config->isWebhookTokenCheckEnabled()) {
20
            return true;
21
        }
22
        return $token === $this->config->getBotToken();
23
    }
24
25
    /**
26
     * @param string $path
27
     * @return string|null
28
     */
29
    protected function resolveTokenFromPath(string $path): ?string
30
    {
31
        $pathParams = explode('/', $path);
32
        return end($pathParams) ?? null;
33
    }
34
35
}
36