Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
irazasyed authored and github-actions[bot] committed Oct 16, 2024
1 parent 177b5b8 commit e3c4769
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 90 deletions.
4 changes: 2 additions & 2 deletions src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Telegram

public function __construct(
?string $token = null,
HttpClient $httpClient = new HttpClient(),
HttpClient $httpClient = new HttpClient,
string $apiBaseUri = 'https://api.telegram.org'
) {
$this->token = $token;
Expand Down Expand Up @@ -117,7 +117,7 @@ public function sendMessage(array $params): ?ResponseInterface
*/
public function sendFile(array $params, string|array $type, bool $multipart = false): ?ResponseInterface
{
return $this->sendRequest('send'.Str::studly((array)$type[0]), $params, $multipart);
return $this->sendRequest('send'.Str::studly((array) $type[0]), $params, $multipart);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/TelegramChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function send(mixed $notifiable, Notification $notification): ?array
$message = TelegramMessage::create($message);
}

if (!$message->canSend()) {
if (! $message->canSend()) {
return null;
}

Expand Down
19 changes: 8 additions & 11 deletions src/TelegramFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use Illuminate\Support\Facades\View;
use NotificationChannels\Telegram\Contracts\TelegramSenderContract;
use NotificationChannels\Telegram\Enums\ParseMode;
use NotificationChannels\Telegram\Exceptions\CouldNotSendNotification;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use NotificationChannels\Telegram\Enums\ParseMode;

/**
* Class TelegramFile.
Expand Down Expand Up @@ -47,8 +47,6 @@ public function content(string $content): self
* Generic method to attach files of any type based on API.
*
* @param resource|StreamInterface|string $file
* @param string $type
* @param string|null $filename
* @return $this
*/
public function file(mixed $file, string $type, ?string $filename = null): self
Expand All @@ -75,7 +73,7 @@ public function file(mixed $file, string $type, ?string $filename = null): self

/**
* Attach an image.
* @param string $file
*
* @return $this
*/
public function photo(string $file): self
Expand All @@ -85,7 +83,7 @@ public function photo(string $file): self

/**
* Attach an audio file.
* @param string $file
*
* @return $this
*/
public function audio(string $file): self
Expand All @@ -95,8 +93,7 @@ public function audio(string $file): self

/**
* Attach a document or any file as document.
* @param string $file
* @param string|null $filename
*
* @return $this
*/
public function document(string $file, ?string $filename = null): self
Expand All @@ -106,7 +103,7 @@ public function document(string $file, ?string $filename = null): self

/**
* Attach a video file.
* @param string $file
*
* @return $this
*/
public function video(string $file): self
Expand All @@ -116,7 +113,7 @@ public function video(string $file): self

/**
* Attach an animation file.
* @param string $file
*
* @return $this
*/
public function animation(string $file): self
Expand All @@ -126,7 +123,7 @@ public function animation(string $file): self

/**
* Attach a voice file.
* @param string $file
*
* @return $this
*/
public function voice(string $file): self
Expand All @@ -136,7 +133,7 @@ public function voice(string $file): self

/**
* Attach a video note file.
* @param string $file
*
* @return $this
*/
public function videoNote(string $file): self
Expand Down
9 changes: 6 additions & 3 deletions src/TelegramMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
use Illuminate\Support\Facades\View;
use JsonException;
use NotificationChannels\Telegram\Contracts\TelegramSenderContract;
use NotificationChannels\Telegram\Exceptions\CouldNotSendNotification;
use NotificationChannels\Telegram\Enums\ParseMode;
use NotificationChannels\Telegram\Exceptions\CouldNotSendNotification;
use Psr\Http\Message\ResponseInterface;

final class TelegramMessage extends TelegramBase implements TelegramSenderContract
{
private const DEFAULT_CHUNK_SIZE = 4096;

private const CHUNK_SEPARATOR = '%#TGMSG#%';

public function __construct(
Expand Down Expand Up @@ -84,9 +85,10 @@ public function shouldChunk(): bool
}

/**
* @return array<int, array<string, mixed>>|ResponseInterface|null
*
* @throws CouldNotSendNotification
* @throws JsonException
* @return array<int, array<string, mixed>>|ResponseInterface|null
*/
public function send(): array|ResponseInterface|null
{
Expand All @@ -96,8 +98,9 @@ public function send(): array|ResponseInterface|null
}

/**
* @param array<string, mixed> $params
* @param array<string, mixed> $params
* @return array<int, array<string, mixed>>
*
* @throws CouldNotSendNotification
* @throws JsonException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/TelegramUpdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function __construct(protected array $payload = []) {}

public static function create(): self
{
return new self();
return new self;
}

/**
Expand Down
77 changes: 31 additions & 46 deletions src/Traits/HasSharedLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ trait HasSharedLogic
/**
* Set the recipient's Chat ID.
*
* @param int|string $chatId The unique identifier for the target chat
* @return static
* @param int|string $chatId The unique identifier for the target chat
*/
public function to(int|string $chatId): static
{
Expand All @@ -54,9 +53,9 @@ public function to(int|string $chatId): static
/**
* Set the keyboard markup for the message.
*
* @param array<string, mixed> $markup The keyboard markup array
* @param array<string, mixed> $markup The keyboard markup array
*
* @throws JsonException When JSON encoding fails
* @return static
*/
public function keyboardMarkup(array $markup): static
{
Expand All @@ -67,8 +66,6 @@ public function keyboardMarkup(array $markup): static

/**
* Unset parse mode of the message.
*
* @return static
*/
public function normal(): static
{
Expand All @@ -80,8 +77,7 @@ public function normal(): static
/**
* Set the parse mode of the message.
*
* @param ParseMode|null $mode The parse mode to use
* @return static
* @param ParseMode|null $mode The parse mode to use
*/
public function parseMode(?ParseMode $mode = null): static
{
Expand All @@ -93,12 +89,12 @@ public function parseMode(?ParseMode $mode = null): static
/**
* Add a normal keyboard button.
*
* @param string $text The text to display on the button
* @param int $columns Number of columns for button layout
* @param bool $requestContact Whether to request user's contact
* @param bool $requestLocation Whether to request user's location
* @param string $text The text to display on the button
* @param int $columns Number of columns for button layout
* @param bool $requestContact Whether to request user's contact
* @param bool $requestLocation Whether to request user's location
*
* @throws JsonException When JSON encoding fails
* @return static
*/
public function keyboard(
string $text,
Expand All @@ -124,11 +120,11 @@ public function keyboard(
/**
* Add an inline button with URL.
*
* @param string $text The text to display on the button
* @param string $url The URL to open when button is pressed
* @param int $columns Number of columns for button layout
* @param string $text The text to display on the button
* @param string $url The URL to open when button is pressed
* @param int $columns Number of columns for button layout
*
* @throws JsonException When JSON encoding fails
* @return static
*/
public function button(string $text, string $url, int $columns = 2): static
{
Expand All @@ -140,11 +136,11 @@ public function button(string $text, string $url, int $columns = 2): static
/**
* Add an inline button with callback data.
*
* @param string $text The text to display on the button
* @param string $callbackData The data to send when button is pressed
* @param int $columns Number of columns for button layout
* @param string $text The text to display on the button
* @param string $callbackData The data to send when button is pressed
* @param int $columns Number of columns for button layout
*
* @throws JsonException When JSON encoding fails
* @return static
*/
public function buttonWithCallback(string $text, string $callbackData, int $columns = 2): static
{
Expand All @@ -159,11 +155,11 @@ public function buttonWithCallback(string $text, string $callbackData, int $colu
/**
* Add an inline button with web app.
*
* @param string $text The text to display on the button
* @param string $url The URL of the Web App to open
* @param int $columns Number of columns for button layout
* @param string $text The text to display on the button
* @param string $url The URL of the Web App to open
* @param int $columns Number of columns for button layout
*
* @throws JsonException When JSON encoding fails
* @return static
*/
public function buttonWithWebApp(string $text, string $url, int $columns = 2): static
{
Expand All @@ -178,8 +174,7 @@ public function buttonWithWebApp(string $text, string $url, int $columns = 2): s
/**
* Send the message silently. Users will receive a notification with no sound.
*
* @param bool $disable Whether to disable the notification sound
* @return static
* @param bool $disable Whether to disable the notification sound
*/
public function disableNotification(bool $disable = true): static
{
Expand All @@ -191,8 +186,7 @@ public function disableNotification(bool $disable = true): static
/**
* Set the Bot Token. Overrides default bot token with the given value for this notification.
*
* @param string $token The bot token to use
* @return static
* @param string $token The bot token to use
*/
public function token(string $token): static
{
Expand All @@ -203,8 +197,6 @@ public function token(string $token): static

/**
* Determine if bot token is given for this notification.
*
* @return bool
*/
public function hasToken(): bool
{
Expand All @@ -214,8 +206,7 @@ public function hasToken(): bool
/**
* Set additional options to pass to sendMessage method.
*
* @param array<string, mixed> $options Additional options
* @return static
* @param array<string, mixed> $options Additional options
*/
public function options(array $options): static
{
Expand All @@ -231,8 +222,7 @@ public function options(array $options): static
* which will be invoked if an exception occurs during the
* notification process. The callback must be a valid Closure.
*
* @param Closure $callback The closure that will handle exceptions.
* @return self
* @param Closure $callback The closure that will handle exceptions.
*/
public function onError(Closure $callback): self
{
Expand All @@ -244,20 +234,17 @@ public function onError(Closure $callback): self
/**
* Set a condition for sending the message.
*
* @param bool|callable $condition The condition to evaluate
* @return static
* @param bool|callable $condition The condition to evaluate
*/
public function sendWhen(bool|callable $condition): static
{
$this->sendCondition = $this->when($condition, fn() => true, fn() => false);
$this->sendCondition = $this->when($condition, fn () => true, fn () => false);

return $this;
}

/**
* Determine if the message can be sent based on the condition.
*
* @return bool
*/
public function canSend(): bool
{
Expand All @@ -266,18 +253,16 @@ public function canSend(): bool

/**
* Determine if chat id is not given.
*
* @return bool
*/
public function toNotGiven(): bool
{
return !isset($this->payload['chat_id']);
return ! isset($this->payload['chat_id']);
}

/**
* Get payload value for given key.
*
* @param string $key The key to retrieve from payload
* @param string $key The key to retrieve from payload
* @return mixed The value from payload or null if not found
*/
public function getPayloadValue(string $key): mixed
Expand Down Expand Up @@ -308,9 +293,9 @@ public function jsonSerialize(): array
/**
* Update the inline keyboard markup.
*
* @param int $columns Number of columns for button layout
* @param int $columns Number of columns for button layout
*
* @throws JsonException When JSON encoding fails
* @return static
*/
private function updateInlineKeyboard(int $columns): static
{
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/TelegramChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use NotificationChannels\Telegram\Tests\TestSupport\TestNotification;

it('can send a message', function () {
$notifiable = new TestNotifiable();
$notification = new TestNotification();
$notifiable = new TestNotifiable;
$notification = new TestNotification;

$expectedResponse = ['ok' => true, 'result' => ['message_id' => 123, 'chat' => ['id' => 12345]]];
$actualResponse = $this->sendMockNotification('sendMessage', $notifiable, $notification, $expectedResponse);
Expand All @@ -19,8 +19,8 @@
self::expectException($exception_class = CouldNotSendNotification::class);
self::expectExceptionMessage($exception_message = 'Some exception');

$notifiable = new TestNotifiable();
$notification = new TestNotification();
$notifiable = new TestNotifiable;
$notification = new TestNotification;

$payload = $notification->toTelegram($notifiable)->toArray();

Expand Down
Loading

0 comments on commit e3c4769

Please sign in to comment.