diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2cfb5a2..eb32fda 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4,10 +4,10 @@ parameters: path: src/Providers/TelegramGitNotifierServiceProvider.php - message: '#Parameter \#1 \$token of method CSlant\\TelegramGitNotifier\\Webhook\:\:setToken\(\) expects string, mixed given\.#' - path: src/Http/Actions/WebhookAction.php + path: src/Services/WebhookService.php - message: '#Parameter \#1 \$url of method CSlant\\TelegramGitNotifier\\Webhook\:\:setUrl\(\) expects string, mixed given\.#' - path: src/Http/Actions/WebhookAction.php + path: src/Services/WebhookService.php - message: '#Parameter \#1 \$prefix of static method Illuminate\\Support\\Facades\\Route::prefix\(\) expects string, mixed given\.#' path: routes/bot.php diff --git a/src/Commands/SetWebhook.php b/src/Commands/SetWebhook.php new file mode 100644 index 0000000..b8ae818 --- /dev/null +++ b/src/Commands/SetWebhook.php @@ -0,0 +1,40 @@ +info($webhookService->setWebhook()); + } catch (WebhookException $e) { + $this->error($e->getMessage()); + } + } +} diff --git a/src/Http/Actions/WebhookAction.php b/src/Http/Actions/WebhookAction.php index 83ac78d..d5c36c8 100644 --- a/src/Http/Actions/WebhookAction.php +++ b/src/Http/Actions/WebhookAction.php @@ -2,18 +2,16 @@ namespace CSlant\LaravelTelegramGitNotifier\Http\Actions; +use CSlant\LaravelTelegramGitNotifier\Services\WebhookService; use CSlant\TelegramGitNotifier\Exceptions\WebhookException; -use CSlant\TelegramGitNotifier\Webhook; class WebhookAction { - protected Webhook $webhook; + protected WebhookService $webhookService; public function __construct() { - $this->webhook = new Webhook(); - $this->webhook->setToken(config('telegram-git-notifier.bot.token')); - $this->webhook->setUrl(config('telegram-git-notifier.app.url')); + $this->webhookService = new WebhookService(); } /** @@ -25,7 +23,7 @@ public function __construct() */ public function set(): string { - return $this->webhook->setWebhook(); + return $this->webhookService->setWebhook(); } /** @@ -37,7 +35,7 @@ public function set(): string */ public function delete(): string { - return $this->webhook->deleteWebHook(); + return $this->webhookService->deleteWebHook(); } /** @@ -49,7 +47,7 @@ public function delete(): string */ public function getUpdates(): string { - return $this->webhook->getUpdates(); + return $this->webhookService->getUpdates(); } /** @@ -61,6 +59,6 @@ public function getUpdates(): string */ public function getWebHookInfo(): string { - return $this->webhook->getWebHookInfo(); + return $this->webhookService->getWebHookInfo(); } } diff --git a/src/Providers/TelegramGitNotifierServiceProvider.php b/src/Providers/TelegramGitNotifierServiceProvider.php index 7ed2954..34bd936 100644 --- a/src/Providers/TelegramGitNotifierServiceProvider.php +++ b/src/Providers/TelegramGitNotifierServiceProvider.php @@ -3,6 +3,7 @@ namespace CSlant\LaravelTelegramGitNotifier\Providers; use CSlant\LaravelTelegramGitNotifier\Commands\ChangeOwnerConfigJson; +use CSlant\LaravelTelegramGitNotifier\Commands\SetWebhook; use Illuminate\Support\ServiceProvider; class TelegramGitNotifierServiceProvider extends ServiceProvider @@ -59,6 +60,7 @@ protected function registerCommands(): void { $this->commands([ ChangeOwnerConfigJson::class, + SetWebhook::class, ]); } diff --git a/src/Services/WebhookService.php b/src/Services/WebhookService.php new file mode 100644 index 0000000..3d6ea8a --- /dev/null +++ b/src/Services/WebhookService.php @@ -0,0 +1,66 @@ +webhook = $webhook ?? new Webhook(); + $this->webhook->setToken(config('telegram-git-notifier.bot.token')); + $this->webhook->setUrl(config('telegram-git-notifier.app.url')); + } + + /** + * Set webhook for telegram bot. + * + * @return string + * + * @throws WebhookException + */ + public function setWebhook(): string + { + return $this->webhook->setWebhook(); + } + + /** + * Delete webhook for telegram bot. + * + * @return string + * + * @throws WebhookException + */ + public function deleteWebHook(): string + { + return $this->webhook->deleteWebHook(); + } + + /** + * Get webhook update. + * + * @return string + * + * @throws WebhookException + */ + public function getUpdates(): string + { + return $this->webhook->getUpdates(); + } + + /** + * Get webhook info. + * + * @return string + * + * @throws WebhookException + */ + public function getWebHookInfo(): string + { + return $this->webhook->getWebHookInfo(); + } +}