Passed
Pull Request — main (#19)
by Tan
02:47
created

IndexAction::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace CSlant\LaravelTelegramGitNotifier\Http\Actions;
4
5
use CSlant\LaravelTelegramGitNotifier\Services\NotificationService;
6
use CSlant\TelegramGitNotifier\Bot;
7
use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException;
8
use CSlant\TelegramGitNotifier\Exceptions\InvalidViewTemplateException;
9
use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException;
10
use CSlant\TelegramGitNotifier\Exceptions\SendNotificationException;
11
use CSlant\TelegramGitNotifier\Notifier;
12
use GuzzleHttp\Client;
13
use Symfony\Component\HttpFoundation\Request;
14
use Telegram;
15
16
class IndexAction
17
{
18
    protected Client $client;
19
20
    protected Bot $bot;
21
22
    protected Notifier $notifier;
23
24
    protected Request $request;
25
26
    /**
27
     * @throws ConfigFileException
28
     */
29
    public function __construct()
30
    {
31
        $this->client = new Client();
32
33
        $telegram = new Telegram(config('telegram-git-notifier.bot.token'));
34
        $this->bot = new Bot($telegram);
35
        $this->notifier = new Notifier();
36
    }
37
38
    /**
39
     * Handle telegram git notifier app.
40
     *
41
     * @return void
42
     *
43
     * @throws InvalidViewTemplateException
44
     * @throws MessageIsEmptyException
45
     * @throws SendNotificationException
46
     */
47
    public function index(): void
48
    {
49
        $sendNotification = new NotificationService(
50
            $this->notifier,
51
            $this->bot->setting
52
        );
53
        $sendNotification->handle();
54
    }
55
}
56