Skip to content

Commit

Permalink
Merge pull request #690 from defstudio/L12
Browse files Browse the repository at this point in the history
laravel 12 support
  • Loading branch information
fabio-ivona authored Feb 22, 2025
2 parents c28fc92 + 1967479 commit a0fcfeb
Show file tree
Hide file tree
Showing 28 changed files with 139 additions and 113 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest]
php: [8.1, 8.2, 8.3, 8.4]
laravel: [10.*, 11.*]
laravel: [10.*, 11.*, 12.*]
stability: [prefer-lowest, prefer-stable]
exclude:
- laravel: 11.*
php: 8.1
- laravel: 12.*
php: 8.1
- php: 8.2
stability: prefer-lowest

Expand Down
25 changes: 12 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@
],
"require": {
"php": "^8.1",
"illuminate/support": "^10.0 | ^11.0",
"illuminate/contracts": "^10.0 | ^11.0",
"illuminate/http": "^10.0 | ^11.0",
"illuminate/support": "^10.0 | ^11.0 | ^12.0",
"illuminate/contracts": "^10.0 | ^11.0 | ^12.0",
"illuminate/http": "^10.0 | ^11.0 | ^12.0",
"spatie/laravel-package-tools": "^1.12.1"
},
"require-dev": {
"ext-sqlite3": "*",
"defstudio/pest-plugin-laravel-expectations": "^v2.1.2",
"friendsofphp/php-cs-fixer": "^v3.13.0",
"defstudio/pest-plugin-laravel-expectations": "^2.1.2",
"friendsofphp/php-cs-fixer": "^3.13.0",
"guzzlehttp/guzzle": "^7.5.0",
"nunomaduro/collision": "^v7.10.0 | ^v8.1.1",
"larastan/larastan": "^1.0.4 | ^2.4.0",
"orchestra/testbench": "^8.0 | ^9.0",
"pestphp/pest": "^v2.34.2",
"pestphp/pest-plugin-laravel": "^v2.3.0",
"pestphp/pest-plugin-mock": "^v2.0.0",
"nunomaduro/collision": "^7.10.0 | ^8.1.1",
"larastan/larastan": "^1.0.4 | ^2.4.0 | ^3.1.0",
"orchestra/testbench": "^8.0 | ^9.0 | ^10.0",
"pestphp/pest": "^2.34.2 | ^3.7.4",
"pestphp/pest-plugin-laravel": "^2.3.0 | ^3.1.0",
"phpstan/extension-installer": "^1.2.0",
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"phpstan/phpstan-phpunit": "^1.2.2",
"phpstan/phpstan-deprecation-rules": "^1.0.0 | ^2.0.1",
"phpstan/phpstan-phpunit": "^1.2.2 | ^2.0.4",
"spatie/laravel-ray": "^1.31.0",
"spatie/pest-plugin-snapshots": "^2.1.0",
"spatie/pest-plugin-test-time": "^2.1.0",
Expand Down
5 changes: 0 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,4 @@ parameters:
- src/Support/Testing

ignoreErrors:
- '#expects string, array\|string\|null given#'
- '#expects string, mixed given#'


checkMissingIterableValueType: true
reportUnmatchedIgnoredErrors: false
1 change: 1 addition & 0 deletions src/Concerns/FakesRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\StreamInterface;

//@phpstan-ignore-next-line
trait FakesRequests
{
/** @var array<int, mixed[]> */
Expand Down
1 change: 1 addition & 0 deletions src/Concerns/HasBotsAndChats.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ public function demoteChatMember(string $userId): Telegraph
->toArray();

foreach ($permissions as $permission => $enabled) {
//@phpstan-ignore-next-line
$telegraph->data[$permission] = $enabled;
}

Expand Down
13 changes: 8 additions & 5 deletions src/Concerns/InteractsWithTelegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ protected function sendRequestToTelegram(): Response
/** @var PendingRequest $request */
$request = $this->files->reduce(
/** @phpstan-ignore-next-line */
function ($request, Attachment $attachment, string $key) {
return $request->attach($key, $attachment->contents(), $attachment->filename());
},
fn ($request, Attachment $attachment, string $key) => $request->attach(
$key,
$attachment->contents(),
$attachment->filename()
),
$request
);

Expand All @@ -63,10 +65,11 @@ protected function prepareData(): array
}

return [$key => json_encode($value)];
})->toArray();
})
->toArray();
}


//@phpstan-ignore-next-line
return $data;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Concerns/InteractsWithWebhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ trait InteractsWithWebhooks
{
private function getWebhookUrl(): string
{
/** @var string|null $customWebhookUrl */
$customWebhookUrl = config('telegraph.custom_webhook_domain', config('telegraph.webhook.domain'));

if ($customWebhookUrl === null) {
Expand Down Expand Up @@ -43,6 +44,8 @@ public function registerWebhook(?bool $dropPendingUpdates = null, ?int $maxConne
$telegraph = clone $this;

$telegraph->endpoint = self::ENDPOINT_SET_WEBHOOK;

//@phpstan-ignore-next-line
$telegraph->data = collect([
'url' => $this->getWebhookUrl(),
'drop_pending_updates' => $dropPendingUpdates,
Expand Down
8 changes: 8 additions & 0 deletions src/Concerns/ManagesKeyboards.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public function keyboard(callable|array|Keyboard $keyboard): Telegraph
}

if (is_array($keyboard)) {
//@phpstan-ignore-next-line
$keyboard = Keyboard::fromArray($keyboard);
}

//@phpstan-ignore-next-line
data_set($telegraph->data, 'reply_markup.inline_keyboard', $keyboard->toArray());

return $telegraph;
Expand All @@ -50,12 +52,16 @@ public function replyKeyboard(callable|array|ReplyKeyboard $keyboard): Telegraph
}

if (is_array($keyboard)) {
//@phpstan-ignore-next-line
$keyboard = ReplyKeyboard::fromArray($keyboard);
}

//@phpstan-ignore-next-line
data_set($telegraph->data, 'reply_markup.keyboard', $keyboard->toArray());

//@phpstan-ignore-next-line
foreach ($keyboard->options() as $option_key => $option_value) {
//@phpstan-ignore-next-line
data_set($telegraph->data, "reply_markup.$option_key", $option_value);
}

Expand Down Expand Up @@ -102,6 +108,8 @@ public function replaceKeyboard(int $messageId, Keyboard|callable $newKeyboard):
$newKeyboard = $newKeyboard(Keyboard::make());
}

assert($newKeyboard instanceof Keyboard);

if ($newKeyboard->isEmpty()) {
$replyMarkup = '';
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/Concerns/SendsAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ public function thumbnail(string $path): self
throw FileException::thumbnailWidthExceeded($width, $maxWidth);
}

/** @var string[] $allowedExt */
$allowedExt = config('telegraph.attachments.thumbnail.allowed_ext', ['jpg']);

assert(is_array($allowedExt));

if (!Str::of($ext = File::extension($path))->lower()->is($allowedExt)) {
throw FileException::invalidThumbnailExtension($ext, $allowedExt);
}
Expand Down
1 change: 0 additions & 1 deletion src/DTO/CallbackQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public static function fromArray(array $data): CallbackQuery
$callbackQuery->data = Str::of($data['data'] ?? '')
->explode(';')
->filter()
/* @phpstan-ignore-next-line */
->mapWithKeys(function (string $entity) {
$entity = explode(':', $entity);
$key = $entity[0];
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ public function toArray(): array
'id' => $this->id,
'type' => $this->type,
'title' => $this->title,
], fn ($value) => $value !== null);
], fn ($value) => $value !== null); //@phpstan-ignore-line
}
}
1 change: 0 additions & 1 deletion src/DTO/ChatInviteLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public static function fromArray(array $data): ChatInviteLink
}

if (isset($data['expire_date'])) {
/* @phpstan-ignore-next-line */
$invite->expireDate = Carbon::createFromTimestamp($data['expire_date']);
}

Expand Down
1 change: 0 additions & 1 deletion src/DTO/ChatJoinRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static function fromArray(array $data): ChatJoinRequest

$request->userChatId = $data['user_chat_id'];

/* @phpstan-ignore-next-line */
$request->date = Carbon::createFromTimestamp($data['date']);

if (isset($data['bio'])) {
Expand Down
1 change: 0 additions & 1 deletion src/DTO/ChatMemberUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public static function fromArray(array $data): ChatMemberUpdate
{
$chatMemberUpdate = new self();

/* @phpstan-ignore-next-line */
$chatMemberUpdate->date = Carbon::createFromTimestamp($data['date']);
/* @phpstan-ignore-next-line */
$chatMemberUpdate->chat = Chat::fromArray($data['chat']);
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public function toArray(): array
'start_parameter' => $this->startParameter,
'currency' => $this->currency,
'total_amount' => $this->totalAmount,
], fn ($value) => $value !== null);
], fn ($value) => $value !== null); //@phpstan-ignore-line
}
}
2 changes: 1 addition & 1 deletion src/DTO/ShippingAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ public function toArray(): array
'street_line1' => $this->streetLine1,
'street_line2' => $this->streetLine2,
'post_code' => $this->postCode,
], fn ($value) => $value !== null);
], fn ($value) => $value !== null); //@phpstan-ignore-line
}
}
2 changes: 1 addition & 1 deletion src/DTO/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ public function toArray(): array
'username' => $this->username,
'language_code' => $this->languageCode,
'is_premium' => $this->isPremium,
], fn ($value) => $value !== null);
], fn ($value) => $value !== null); //@phpstan-ignore-line
}
}
25 changes: 13 additions & 12 deletions src/Facades/Telegraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace DefStudio\Telegraph\Facades;

use DefStudio\Telegraph\Contracts\Downloadable;
use DefStudio\Telegraph\DTO\InlineQueryResult;
use DefStudio\Telegraph\Keyboard\Keyboard;
use DefStudio\Telegraph\Models\TelegraphBot;
use DefStudio\Telegraph\Models\TelegraphChat;
Expand All @@ -27,7 +28,7 @@
* @method static \DefStudio\Telegraph\Telegraph markdownV2(string $message)
* @method static \DefStudio\Telegraph\Telegraph registerWebhook()
* @method static \DefStudio\Telegraph\Telegraph unregisterWebhook(bool $dropPendingUpdates = false)
* @method static \DefStudio\Telegraph\Telegraph registerBotCommands(array $commands)
* @method static \DefStudio\Telegraph\Telegraph registerBotCommands(array<string, string> $commands)
* @method static \DefStudio\Telegraph\Telegraph getRegisteredCommands()
* @method static \DefStudio\Telegraph\Telegraph unregisterBotCommands()
* @method static \DefStudio\Telegraph\Telegraph getWebhookDebugInfo()
Expand All @@ -41,7 +42,7 @@
* @method static \DefStudio\Telegraph\Telegraph unpinAllMessages()
* @method static \DefStudio\Telegraph\Telegraph editCaption(string $messageId)
* @method static \DefStudio\Telegraph\Telegraph editMedia(string $messageId)
* @method static \DefStudio\Telegraph\Telegraph answerInlineQuery(string $inlineQueryID, array $results)
* @method static \DefStudio\Telegraph\Telegraph answerInlineQuery(string $inlineQueryID, InlineQueryResult[] $results)
* @method static \DefStudio\Telegraph\Telegraph document(string $path, string $filename = null)
* @method static \DefStudio\Telegraph\Telegraph photo(string $path, string $filename = null)
* @method static \DefStudio\Telegraph\Telegraph animation(string $path, string $filename = null)
Expand All @@ -51,14 +52,14 @@
* @method static \DefStudio\Telegraph\Telegraph video(string $path, string $filename = null)
* @method static \DefStudio\Telegraph\Telegraph audio(string $path, string $filename = null)
* @method static \DefStudio\Telegraph\Telegraph dice()
* @method static \DefStudio\Telegraph\Telegraph mediaGroup(string $path, array $media)
* @method static \DefStudio\Telegraph\Telegraph mediaGroup(string $path, array<int|string, array<mixed>> $media)
* @method static \DefStudio\Telegraph\Telegraph botUpdates()
* @method static \DefStudio\Telegraph\Telegraph botInfo()
* @method static \DefStudio\Telegraph\Telegraph setBaseUrl(string|null $url)
* @method static \DefStudio\Telegraph\Telegraph setTitle(string $title)
* @method static \DefStudio\Telegraph\Telegraph setDescription(string $description)
* @method static \DefStudio\Telegraph\Telegraph setChatPhoto(string $path)
* @method static \DefStudio\Telegraph\Telegraph setMessageReaction(int $message_id, array $reaction, bool $isBig = false)
* @method static \DefStudio\Telegraph\Telegraph setMessageReaction(int $message_id, array<string, string> $reaction, bool $isBig = false)
* @method static \DefStudio\Telegraph\Telegraph reactWithEmoji(int $message_id, string $emoji, bool $isBig = false)
* @method static \DefStudio\Telegraph\Telegraph reactWithCustomEmoji(int $message_id, string $customEmoji, bool $isBig = false)
* @method static \DefStudio\Telegraph\Telegraph chatInfo()
Expand All @@ -68,11 +69,11 @@
* @method static \DefStudio\Telegraph\Telegraph revokeChatInviteLink()
* @method static \DefStudio\Telegraph\Telegraph chatMemberCount()
* @method static \DefStudio\Telegraph\Telegraph chatMember(string $userId)
* @method static \DefStudio\Telegraph\Telegraph setChatPermissions(array $permissions)
* @method static \DefStudio\Telegraph\Telegraph setChatPermissions(array<int|string, string|bool> $permissions)
* @method static \DefStudio\Telegraph\Telegraph banChatMember(string $userId)
* @method static \DefStudio\Telegraph\Telegraph unbanChatMember(string $userId)
* @method static \DefStudio\Telegraph\Telegraph restrictChatMember(string $userId, array $permissions)
* @method static \DefStudio\Telegraph\Telegraph promoteChatMember(string $userId, array $permissions)
* @method static \DefStudio\Telegraph\Telegraph restrictChatMember(string $userId, array<int|string, string|bool> $permissions)
* @method static \DefStudio\Telegraph\Telegraph promoteChatMember(string $userId, array<int|string, string|bool> $permissions)
* @method static \DefStudio\Telegraph\Telegraph demoteChatMember(string $userId)
* @method static \DefStudio\Telegraph\Telegraph userProfilePhotos(string $userId)
* @method static \DefStudio\Telegraph\Telegraph chatMenuButton()
Expand All @@ -87,14 +88,14 @@
* @method static TelegraphQuizPayload quiz(string $question)
* @method static string store(Downloadable $attachment, string $path, string $filename = null)
* @method static void dumpSentData()
* @method static void assertSentData(string $endpoint, array $data = null, bool $exact = true)
* @method static void assertSentFiles(string $endpoint, array $files = null)
* @method static void assertSentData(string $endpoint, mixed[] $data = null, bool $exact = true)
* @method static void assertSentFiles(string $endpoint, mixed[] $files = null)
* @method static void assertSent(string $message, bool $exact = true)
* @method static void assertNotSent(string $message, bool $exact = true)
* @method static void assertNothingSent()
* @method static void assertRegisteredWebhook(array $data = null, bool $exact = true)
* @method static void assertUnregisteredWebhook(array $data = null, bool $exact = true)
* @method static void assertRequestedWebhookDebugInfo(array $data = null, bool $exact = true)
* @method static void assertRegisteredWebhook(mixed[] $data = null, bool $exact = true)
* @method static void assertUnregisteredWebhook(mixed[] $data = null, bool $exact = true)
* @method static void assertRequestedWebhookDebugInfo(mixed[] $data = null, bool $exact = true)
* @method static void assertRepliedWebhook(string $message)
* @method static void assertRepliedWebhookIsAlert()
* @method static void assertStoredFile(string $fileId)
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/SendRequestToTelegramJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function handle(): void

/** @var PendingRequest $request */
$request = $this->files->reduce(
/** @phpstan-ignore-next-line */
function ($request, Attachment $attachment, string $key) {
//@phpstan-ignore-next-line
return $request->attach($key, $attachment->contents(), $attachment->filename());
},
$request
Expand Down
2 changes: 1 addition & 1 deletion src/Keyboard/Keyboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public function deleteButton(string $label): Keyboard
{
$clone = $this->clone();

/* @phpstan-ignore-next-line */
$clone->buttons = $clone->buttons->reject(fn (Button $button) => $button->label() == $label);

return $clone;
Expand Down Expand Up @@ -233,6 +232,7 @@ public function toArray(): array

$keyboard[] = $row;

//@phpstan-ignore-next-line
return $this->rtl ? array_map('array_reverse', $keyboard) : $keyboard;
}
}
2 changes: 1 addition & 1 deletion src/Keyboard/ReplyKeyboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public function deleteButton(string $label): self
{
$clone = $this->clone();

/* @phpstan-ignore-next-line */
$clone->buttons = $clone->buttons->reject(fn (ReplyButton $button) => $button->label() == $label);

return $clone;
Expand Down Expand Up @@ -277,6 +276,7 @@ public function toArray(): array

$keyboard[] = $row;

//@phpstan-ignore-next-line
return $this->rtl ? array_map('array_reverse', $keyboard) : $keyboard;
}

Expand Down
10 changes: 2 additions & 8 deletions src/Models/TelegraphBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @property string $name
* @property Carbon $created_at
* @property Carbon $updated_at
* @property-read Collection<TelegraphChat> $chats
* @property-read Collection<int, TelegraphChat> $chats
*/
class TelegraphBot extends Model implements Storable
{
Expand Down Expand Up @@ -76,20 +76,14 @@ public function getRouteKeyName(): string
public static function fromId(int|null $id = null): TelegraphBot
{
if (empty($id)) {
/** @noinspection PhpIncompatibleReturnTypeInspection */
/** @phpstan-ignore-next-line */
return self::query()->sole();
}

/** @noinspection PhpIncompatibleReturnTypeInspection */
/** @phpstan-ignore-next-line */
return self::query()->findOrFail($id);
}

public static function fromToken(string $token): TelegraphBot
{
/** @noinspection PhpIncompatibleReturnTypeInspection */
/** @phpstan-ignore-next-line */
return self::query()->where('token', $token)->sole();
}

Expand All @@ -98,7 +92,7 @@ public static function fromToken(string $token): TelegraphBot
*/
public function chats(): HasMany
{
/** @phpstan-ignore-next-line */
//@phpstan-ignore-next-line
return $this->hasMany(config('telegraph.models.chat'), 'telegraph_bot_id');
}

Expand Down
Loading

0 comments on commit a0fcfeb

Please sign in to comment.