1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace CSlant\LaravelTelegramGitNotifier\Http\Actions; |
6
|
|
|
|
7
|
|
|
use CSlant\LaravelTelegramGitNotifier\Services\CallbackService; |
8
|
|
|
use CSlant\LaravelTelegramGitNotifier\Services\CommandService; |
9
|
|
|
use CSlant\LaravelTelegramGitNotifier\Services\NotificationService; |
10
|
|
|
use CSlant\TelegramGitNotifier\Bot; |
11
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\BotException; |
12
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\CallbackException; |
13
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException; |
14
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\EntryNotFoundException; |
15
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\InvalidViewTemplateException; |
16
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException; |
17
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\SendNotificationException; |
18
|
|
|
use CSlant\TelegramGitNotifier\Notifier; |
19
|
|
|
use GuzzleHttp\Client; |
20
|
|
|
use GuzzleHttp\ClientInterface; |
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
22
|
|
|
use Telegram\Telegram as TelegramSDK; |
|
|
|
|
23
|
|
|
|
24
|
|
|
class IndexAction |
25
|
|
|
{ |
26
|
|
|
public function __construct( |
27
|
|
|
private ClientInterface $client, |
28
|
|
|
private Bot $bot, |
29
|
|
|
private Notifier $notifier, |
30
|
|
|
private Request $request |
31
|
|
|
) { |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Create a new instance with default dependencies. |
36
|
|
|
* |
37
|
|
|
* @throws ConfigFileException |
38
|
|
|
*/ |
39
|
|
|
public static function createDefault(): self |
40
|
|
|
{ |
41
|
|
|
return new self( |
42
|
|
|
new Client(), |
43
|
|
|
new Bot(new TelegramSDK(config('telegram-git-notifier.bot.token'))), |
44
|
|
|
new Notifier(), |
45
|
|
|
Request::createFromGlobals() |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Handle telegram git notifier app. |
51
|
|
|
* |
52
|
|
|
* @throws InvalidViewTemplateException |
53
|
|
|
* @throws MessageIsEmptyException |
54
|
|
|
* @throws SendNotificationException |
55
|
|
|
* @throws BotException |
56
|
|
|
* @throws CallbackException |
57
|
|
|
* @throws EntryNotFoundException |
58
|
|
|
*/ |
59
|
|
|
public function __invoke(): void |
60
|
|
|
{ |
61
|
|
|
if ($this->bot->isCallback()) { |
62
|
|
|
$this->handleCallback(); |
63
|
|
|
|
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if ($this->shouldHandleCommand()) { |
68
|
|
|
$this->handleCommand(); |
69
|
|
|
|
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$this->handleNotification(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Handle callback actions. |
78
|
|
|
* |
79
|
|
|
* @throws CallbackException |
80
|
|
|
* @throws EntryNotFoundException |
81
|
|
|
* @throws InvalidViewTemplateException |
82
|
|
|
* @throws MessageIsEmptyException |
83
|
|
|
*/ |
84
|
|
|
private function handleCallback(): void |
85
|
|
|
{ |
86
|
|
|
$callbackAction = new CallbackService($this->bot); |
|
|
|
|
87
|
|
|
$callbackAction->handle(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Handle command messages. |
92
|
|
|
* |
93
|
|
|
* @throws EntryNotFoundException |
94
|
|
|
* @throws MessageIsEmptyException |
95
|
|
|
*/ |
96
|
|
|
private function handleCommand(): void |
97
|
|
|
{ |
98
|
|
|
if (!$this->bot->isMessage() || !$this->bot->isOwner()) { |
99
|
|
|
return; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$commandAction = new CommandService($this->bot); |
|
|
|
|
103
|
|
|
$commandAction->handle(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Handle notification sending. |
108
|
|
|
* |
109
|
|
|
* @throws InvalidViewTemplateException |
110
|
|
|
* @throws MessageIsEmptyException |
111
|
|
|
* @throws SendNotificationException |
112
|
|
|
*/ |
113
|
|
|
private function handleNotification(): void |
114
|
|
|
{ |
115
|
|
|
$notificationService = new NotificationService( |
|
|
|
|
116
|
|
|
$this->notifier, |
117
|
|
|
$this->bot->setting |
118
|
|
|
); |
119
|
|
|
$notificationService->handle(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Check if the current message should be handled as a command. |
124
|
|
|
*/ |
125
|
|
|
private function shouldHandleCommand(): bool |
126
|
|
|
{ |
127
|
|
|
return $this->bot->isMessage() && $this->bot->isOwner(); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths