IndexAction   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 19
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A __invoke() 0 18 4
1
<?php
2
3
namespace CSlant\TelegramGitNotifierApp\Http\Actions;
4
5
use CSlant\TelegramGitNotifier\Bot;
6
use CSlant\TelegramGitNotifier\Exceptions\BotException;
7
use CSlant\TelegramGitNotifier\Exceptions\CallbackException;
8
use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException;
9
use CSlant\TelegramGitNotifier\Exceptions\EntryNotFoundException;
10
use CSlant\TelegramGitNotifier\Exceptions\InvalidViewTemplateException;
11
use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException;
12
use CSlant\TelegramGitNotifier\Exceptions\SendNotificationException;
13
use CSlant\TelegramGitNotifier\Notifier;
14
use CSlant\TelegramGitNotifierApp\Services\CallbackService;
15
use CSlant\TelegramGitNotifierApp\Services\CommandService;
16
use CSlant\TelegramGitNotifierApp\Services\NotificationService;
17
use GuzzleHttp\Client;
18
use Symfony\Component\HttpFoundation\Request;
19
use Telegram;
20
21
class IndexAction
22
{
23
    protected Client $client;
24
25
    protected Bot $bot;
26
27
    protected Notifier $notifier;
28
29
    protected Request $request;
30
31
    /**
32
     * @throws ConfigFileException
33
     */
34
    public function __construct()
35
    {
36
        $this->client = new Client();
37
38
        $telegram = new Telegram(config('telegram-git-notifier.bot.token'));
39
        $this->bot = new Bot($telegram);
40
        $this->notifier = new Notifier();
41
    }
42
43
    /**
44
     * Handle telegram git notifier app
45
     *
46
     * @return void
47
     * @throws EntryNotFoundException
48
     * @throws InvalidViewTemplateException
49
     * @throws MessageIsEmptyException
50
     * @throws SendNotificationException
51
     * @throws BotException
52
     * @throws CallbackException
53
     */
54
    public function __invoke(): void
55
    {
56
        if ($this->bot->isCallback()) {
57
            $callbackAction = new CallbackService($this->bot);
58
            $callbackAction->handle();
59
60
            return;
61
        }
62
63
        if ($this->bot->isMessage() && $this->bot->isOwner()) {
64
            $commandAction = new CommandService($this->bot);
65
            $commandAction->handle();
66
67
            return;
68
        }
69
70
        $sendNotification = new NotificationService($this->notifier, $this->bot->setting);
71
        $sendNotification->handle();
72
    }
73
}
74