WebhookService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
cc 1
eloc 3
c 4
b 1
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace CSlant\LaravelTelegramGitNotifier\Services;
4
5
use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
6
use CSlant\TelegramGitNotifier\Interfaces\WebhookInterface;
7
use CSlant\TelegramGitNotifier\Webhook;
8
9
class WebhookService
10
{
11
    protected WebhookInterface $webhookInterface;
12
13
    public function __construct(?WebhookInterface $webhookInterface = null)
14
    {
15
        $this->webhookInterface = $webhookInterface ?? new Webhook();
16
        $this->webhookInterface->setToken(config('telegram-git-notifier.bot.token'));
17
        $this->webhookInterface->setUrl(config('telegram-git-notifier.app.url'));
18
    }
19
20
    /**
21
     * Set webhook for telegram bot.
22
     *
23
     * @return string
24
     *
25
     * @throws WebhookException
26
     */
27
    public function setWebhook(): string
28
    {
29
        return $this->webhookInterface->setWebhook();
30
    }
31
32
    /**
33
     * Delete webhook for telegram bot.
34
     *
35
     * @return string
36
     *
37
     * @throws WebhookException
38
     */
39
    public function deleteWebHook(): string
40
    {
41
        return $this->webhookInterface->deleteWebHook();
42
    }
43
44
    /**
45
     * Get webhook update.
46
     *
47
     * @return string
48
     *
49
     * @throws WebhookException
50
     */
51
    public function getUpdates(): string
52
    {
53
        return $this->webhookInterface->getUpdates();
54
    }
55
56
    /**
57
     * Get webhook info.
58
     *
59
     * @return string
60
     *
61
     * @throws WebhookException
62
     */
63
    public function getWebHookInfo(): string
64
    {
65
        return $this->webhookInterface->getWebHookInfo();
66
    }
67
}
68