Skip to content

Commit

Permalink
Merge pull request #30 from tanhongit/test
Browse files Browse the repository at this point in the history
Update exceptions
  • Loading branch information
tanhongit authored Nov 7, 2023
2 parents a17612b + 91e653f commit 9cf3c8b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 28 deletions.
17 changes: 4 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
/vendor
vendor
composer.lock
composer.phar
.DS_Store
/node_modules
/public/storage
/storage/*.key
Thumbs.db
/bower_components
bower_components

.env
.env.backup
.idea
.vscode

.vagrant
Homestead.json
Homestead.yaml
npm-debug.log

.phpunit.cache
.phpunit.result.cache
/storage/.license
/storage/fonts
/storage/installing
/storage/installed
/storage/json
/log
storage
log

package-lock.json
yarn.lock
Expand Down
6 changes: 3 additions & 3 deletions src/Constants/NotificationConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

final class NotificationConstant
{
// Separation between chat id pairs
/** @var string Separation between chat id pairs */
public const CHAT_ID_PAIRS_SEPARATOR = ';';

// Separation between chat id and thread id
/** @var string Separation between chat id and thread id */
public const CHAT_THREAD_ID_SEPARATOR = ':';

// Separation between thread id
/** @var string Separation between thread ids */
public const THREAD_ID_SEPARATOR = ',';
}
18 changes: 18 additions & 0 deletions src/Exceptions/BotException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace CSlant\TelegramGitNotifier\Exceptions;

use Exception;

final class BotException extends TelegramGitNotifierException
{
public static function editMessageText(Exception $exception): self
{
return new self('Error editing message text: ' . $exception->getMessage());
}

public static function editMessageReplyMarkup(Exception $exception): self
{
return new self('Error sending message: ' . $exception->getMessage());
}
}
11 changes: 4 additions & 7 deletions src/Exceptions/CallbackException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

namespace CSlant\TelegramGitNotifier\Exceptions;

use Exception;

final class CallbackException extends TelegramGitNotifierException
{
public static function isEmpty(): self
{
return new self('Callback is empty');
}

public static function invalid(): self
public static function answer(Exception $exception): self
{
return new self('Callback is invalid');
return new self('Error answering callback query: ' . $exception->getMessage());
}
}
2 changes: 1 addition & 1 deletion src/Helpers/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use CSlant\TelegramGitNotifier\Exceptions\InvalidViewTemplateException;
use Throwable;

class ConfigHelper
final class ConfigHelper
{
/**
* @var array<string, mixed>
Expand Down
6 changes: 6 additions & 0 deletions src/Interfaces/SettingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace CSlant\TelegramGitNotifier\Interfaces;

use CSlant\TelegramGitNotifier\Constants\EventConstant;
use CSlant\TelegramGitNotifier\Exceptions\BotException;
use CSlant\TelegramGitNotifier\Exceptions\InvalidViewTemplateException;
use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException;
use CSlant\TelegramGitNotifier\Trait\BotSettingTrait;
Expand Down Expand Up @@ -65,6 +66,7 @@ public function getEndKeyboard(string $platform, ?string $parentEvent = null): a
*
* @return void
* @throws InvalidViewTemplateException
* @throws BotException
* @see EventSettingTrait::eventHandle()
*/
public function eventHandle(?string $callback = null, ?string $platform = null, string $platformFile = null): void;
Expand All @@ -90,6 +92,7 @@ public function getPlatformFromCallback(?string $callback, ?string $platform): s
* @return bool
* @see EventSettingTrait::sendSettingEventMessage()
* @throws InvalidViewTemplateException
* @throws BotException
*/
public function sendSettingEventMessage(string $platform, ?string $callback = null, ?string $view = null): bool;

Expand All @@ -113,6 +116,7 @@ public function getEventFromCallback(?string $callback): string;
* @return bool
* @see EventSettingTrait::handleEventWithActions()
* @throws InvalidViewTemplateException
* @throws BotException
*/
public function handleEventWithActions(
string $event,
Expand All @@ -129,6 +133,7 @@ public function handleEventWithActions(
*
* @return void
* @throws InvalidViewTemplateException
* @throws BotException
* @see EventSettingTrait::handleEventUpdate()
*/
public function handleEventUpdate(string $event, string $platform, string $platFormFile = null): void;
Expand All @@ -142,6 +147,7 @@ public function handleEventUpdate(string $event, string $platform, string $platF
*
* @return void
* @throws InvalidViewTemplateException
* @throws BotException
* @see EventSettingTrait::eventUpdateHandle()
*/
public function eventUpdateHandle(string $event, string $platform, string $platFormFile = null): void;
Expand Down
8 changes: 7 additions & 1 deletion src/Interfaces/Structures/AppInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CSlant\TelegramGitNotifier\Interfaces\Structures;

use CSlant\TelegramGitNotifier\Exceptions\BotException;
use CSlant\TelegramGitNotifier\Exceptions\CallbackException;
use CSlant\TelegramGitNotifier\Exceptions\EntryNotFoundException;
use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException;

Expand Down Expand Up @@ -35,12 +37,14 @@ public function sendPhoto(string $photo = '', array $caption = []): void;
* Send callback response to telegram (show alert)
*
* @param string|null $text
* @param array $options
*
* @return void
* @throws MessageIsEmptyException
* @throws CallbackException
* @see App::answerCallbackQuery()
*/
public function answerCallbackQuery(string $text = null): void;
public function answerCallbackQuery(string $text = null, array $options = []): void;

/**
* Edit message text and reply markup
Expand All @@ -49,6 +53,7 @@ public function answerCallbackQuery(string $text = null): void;
* @param array $options
*
* @return void
* @throws BotException
* @see App::editMessageText()
*/
public function editMessageText(string $text = null, array $options = []): void;
Expand All @@ -59,6 +64,7 @@ public function editMessageText(string $text = null, array $options = []): void;
* @param array $options
*
* @return void
* @throws BotException
* @see App::editMessageReplyMarkup()
*/
public function editMessageReplyMarkup(array $options = []): void;
Expand Down
8 changes: 5 additions & 3 deletions src/Structures/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CSlant\TelegramGitNotifier\Structures;

use CSlant\TelegramGitNotifier\Exceptions\BotException;
use CSlant\TelegramGitNotifier\Exceptions\CallbackException;
use CSlant\TelegramGitNotifier\Exceptions\EntryNotFoundException;
use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException;
use Exception;
Expand Down Expand Up @@ -76,7 +78,7 @@ public function answerCallbackQuery(string $text = null, array $options = []): v
], $options);
$this->telegram->answerCallbackQuery($options);
} catch (Exception $e) {
error_log("Error answering callback query: " . $e->getMessage());
throw CallbackException::answer($e);
}
}

Expand All @@ -91,7 +93,7 @@ public function editMessageText(

$this->telegram->editMessageText($content);
} catch (Exception $e) {
error_log($e->getMessage());
throw BotException::editMessageText($e);
}
}

Expand All @@ -102,7 +104,7 @@ public function editMessageReplyMarkup(array $options = []): void
$this->setCallbackContentMessage($options)
);
} catch (Exception $e) {
error_log($e->getMessage());
throw BotException::editMessageReplyMarkup($e);
}
}

Expand Down

0 comments on commit 9cf3c8b

Please sign in to comment.