Skip to content

Commit fc57167

Browse files
committed
Revert "refactor: optimize services"
This reverts commit f9575da.
1 parent 89e9cc3 commit fc57167

File tree

8 files changed

+218
-521
lines changed

8 files changed

+218
-521
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737
},
3838
"require": {
39-
"php": "^8.2",
39+
"php": "^8.1",
4040
"cslant/telegram-git-notifier": "^v1.4"
4141
},
4242
"require-dev": {

src/Http/Actions/IndexAction.php

Lines changed: 23 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace CSlant\LaravelTelegramGitNotifier\Http\Actions;
64

75
use CSlant\LaravelTelegramGitNotifier\Services\CallbackService;
@@ -17,38 +15,36 @@
1715
use CSlant\TelegramGitNotifier\Exceptions\SendNotificationException;
1816
use CSlant\TelegramGitNotifier\Notifier;
1917
use GuzzleHttp\Client;
20-
use GuzzleHttp\ClientInterface;
2118
use Symfony\Component\HttpFoundation\Request;
22-
use Telegram\Telegram as TelegramSDK;
19+
use Telegram;
2320

2421
class IndexAction
2522
{
26-
public function __construct(
27-
private ClientInterface $client,
28-
private Bot $bot,
29-
private Notifier $notifier,
30-
private Request $request
31-
) {
32-
}
23+
protected Client $client;
24+
25+
protected Bot $bot;
26+
27+
protected Notifier $notifier;
28+
29+
protected Request $request;
3330

3431
/**
35-
* Create a new instance with default dependencies.
36-
*
3732
* @throws ConfigFileException
3833
*/
39-
public static function createDefault(): self
34+
public function __construct()
4035
{
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-
);
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();
4741
}
4842

4943
/**
5044
* Handle telegram git notifier app.
5145
*
46+
* @return void
47+
*
5248
* @throws InvalidViewTemplateException
5349
* @throws MessageIsEmptyException
5450
* @throws SendNotificationException
@@ -59,69 +55,23 @@ public static function createDefault(): self
5955
public function __invoke(): void
6056
{
6157
if ($this->bot->isCallback()) {
62-
$this->handleCallback();
63-
return;
64-
}
58+
$callbackAction = new CallbackService($this->bot);
59+
$callbackAction->handle();
6560

66-
if ($this->shouldHandleCommand()) {
67-
$this->handleCommand();
6861
return;
6962
}
7063

71-
$this->handleNotification();
72-
}
73-
74-
/**
75-
* Handle callback actions.
76-
*
77-
* @throws CallbackException
78-
* @throws EntryNotFoundException
79-
* @throws InvalidViewTemplateException
80-
* @throws MessageIsEmptyException
81-
*/
82-
private function handleCallback(): void
83-
{
84-
$callbackAction = new CallbackService($this->bot);
85-
$callbackAction->handle();
86-
}
64+
if ($this->bot->isMessage() && $this->bot->isOwner()) {
65+
$commandAction = new CommandService($this->bot);
66+
$commandAction->handle();
8767

88-
/**
89-
* Handle command messages.
90-
*
91-
* @throws EntryNotFoundException
92-
* @throws MessageIsEmptyException
93-
*/
94-
private function handleCommand(): void
95-
{
96-
if (!$this->bot->isMessage() || !$this->bot->isOwner()) {
9768
return;
9869
}
9970

100-
$commandAction = new CommandService($this->bot);
101-
$commandAction->handle();
102-
}
103-
104-
/**
105-
* Handle notification sending.
106-
*
107-
* @throws InvalidViewTemplateException
108-
* @throws MessageIsEmptyException
109-
* @throws SendNotificationException
110-
*/
111-
private function handleNotification(): void
112-
{
113-
$notificationService = new NotificationService(
71+
$sendNotification = new NotificationService(
11472
$this->notifier,
11573
$this->bot->setting
11674
);
117-
$notificationService->handle();
118-
}
119-
120-
/**
121-
* Check if the current message should be handled as a command.
122-
*/
123-
private function shouldHandleCommand(): bool
124-
{
125-
return $this->bot->isMessage() && $this->bot->isOwner();
75+
$sendNotification->handle();
12676
}
12777
}

src/Http/Actions/WebhookAction.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace CSlant\LaravelTelegramGitNotifier\Http\Actions;
64

75
use CSlant\LaravelTelegramGitNotifier\Services\WebhookService;
86
use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
97

108
class WebhookAction
119
{
12-
public function __construct(
13-
private readonly WebhookService $webhookService
14-
) {
10+
protected WebhookService $webhookService;
11+
12+
public function __construct()
13+
{
14+
$this->webhookService = new WebhookService();
1515
}
1616

1717
/**
1818
* Set webhook for telegram bot.
1919
*
20+
* @return string
21+
*
2022
* @throws WebhookException
2123
*/
2224
public function set(): string
@@ -27,6 +29,8 @@ public function set(): string
2729
/**
2830
* Delete webhook for telegram bot.
2931
*
32+
* @return string
33+
*
3034
* @throws WebhookException
3135
*/
3236
public function delete(): string
@@ -37,6 +41,8 @@ public function delete(): string
3741
/**
3842
* Get webhook update.
3943
*
44+
* @return string
45+
*
4046
* @throws WebhookException
4147
*/
4248
public function getUpdates(): string
@@ -47,6 +53,8 @@ public function getUpdates(): string
4753
/**
4854
* Get webhook info.
4955
*
56+
* @return string
57+
*
5058
* @throws WebhookException
5159
*/
5260
public function getWebHookInfo(): string

0 commit comments

Comments
 (0)