diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 8a6cf6124..3e752d0ca 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -16,7 +16,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.4' coverage: none - name: Install composer dependencies diff --git a/composer.json b/composer.json index 92f5a1c89..c84431d02 100644 --- a/composer.json +++ b/composer.json @@ -54,8 +54,8 @@ }, "scripts": { "x-ray": "vendor/bin/x-ray .", - "lint": "vendor/bin/php-cs-fixer fix -v", - "test:lint": "vendor/bin/php-cs-fixer fix -v --dry-run", + "lint": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix -v", + "test:lint": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix -v --dry-run", "test:types": "vendor/bin/phpstan analyse --ansi --memory-limit=-1", "test:unit": "vendor/bin/pest --colors=always --exclude-group=sandbox", "test:sandbox": "vendor/bin/pest --colors=always --group=sandbox", diff --git a/src/Concerns/HasStorage.php b/src/Concerns/HasStorage.php index 1b13b2ab6..4d159257a 100644 --- a/src/Concerns/HasStorage.php +++ b/src/Concerns/HasStorage.php @@ -9,7 +9,7 @@ trait HasStorage { - public function storage(string $driver = null): StorageDriver + public function storage(string|null $driver = null): StorageDriver { $driver ??= config('telegraph.storage.default'); diff --git a/src/Contracts/Storable.php b/src/Contracts/Storable.php index 901c483fa..2f7dd08c1 100644 --- a/src/Contracts/Storable.php +++ b/src/Contracts/Storable.php @@ -4,7 +4,7 @@ interface Storable { - public function storage(string $driver = null): StorageDriver; + public function storage(string|null $driver = null): StorageDriver; public function storageKey(): string|int; } diff --git a/src/DTO/InlineQueryResultContact.php b/src/DTO/InlineQueryResultContact.php index 007388f04..b3d29378c 100644 --- a/src/DTO/InlineQueryResultContact.php +++ b/src/DTO/InlineQueryResultContact.php @@ -20,7 +20,7 @@ class InlineQueryResultContact extends InlineQueryResult protected string|null $thumbUrl = null; protected string|null $parseMode = null; - public static function make(string $id, string $phoneNumber, string $firstName, string $message = null): InlineQueryResultContact + public static function make(string $id, string $phoneNumber, string $firstName, string|null $message = null): InlineQueryResultContact { $result = new InlineQueryResultContact(); $result->id = $id; diff --git a/src/DTO/InlineQueryResultLocation.php b/src/DTO/InlineQueryResultLocation.php index 3895ccf75..c81828d0b 100644 --- a/src/DTO/InlineQueryResultLocation.php +++ b/src/DTO/InlineQueryResultLocation.php @@ -23,7 +23,7 @@ class InlineQueryResultLocation extends InlineQueryResult protected float|null $horizontalAccuracy = null; protected string|null $parseMode = null; - public static function make(string $id, string $title, float $latitude, float $longitude, string $message = null): InlineQueryResultLocation + public static function make(string $id, string $title, float $latitude, float $longitude, string|null $message = null): InlineQueryResultLocation { $result = new InlineQueryResultLocation(); $result->id = $id; diff --git a/src/DTO/InlineQueryResultVenue.php b/src/DTO/InlineQueryResultVenue.php index fa1177e15..7811da647 100644 --- a/src/DTO/InlineQueryResultVenue.php +++ b/src/DTO/InlineQueryResultVenue.php @@ -23,7 +23,7 @@ class InlineQueryResultVenue extends InlineQueryResult protected int|null $thumbWidth = null; protected int|null $thumbHeight = null; - public static function make(string $id, string $title, float $latitude, float $longitude, string $address, string $message = null): InlineQueryResultVenue + public static function make(string $id, string $title, float $latitude, float $longitude, string $address, string|null $message = null): InlineQueryResultVenue { $result = new InlineQueryResultVenue(); $result->id = $id; diff --git a/src/Models/TelegraphBot.php b/src/Models/TelegraphBot.php index dd266c38c..a1749e0f7 100644 --- a/src/Models/TelegraphBot.php +++ b/src/Models/TelegraphBot.php @@ -36,6 +36,7 @@ */ class TelegraphBot extends Model implements Storable { + /** @use HasFactory */ use HasFactory; use HasStorage; @@ -72,7 +73,7 @@ public function getRouteKeyName(): string return 'token'; } - public static function fromId(int $id = null): TelegraphBot + public static function fromId(int|null $id = null): TelegraphBot { if (empty($id)) { /** @noinspection PhpIncompatibleReturnTypeInspection */ @@ -93,7 +94,7 @@ public static function fromToken(string $token): TelegraphBot } /** - * @return HasMany + * @return HasMany */ public function chats(): HasMany { @@ -101,7 +102,7 @@ public function chats(): HasMany return $this->hasMany(config('telegraph.models.chat'), 'telegraph_bot_id'); } - public function registerWebhook(bool $dropPendingUpdates = null, int $maxConnections = null, string $secretToken = null): Telegraph + public function registerWebhook(bool|null $dropPendingUpdates = null, int|null $maxConnections = null, string|null $secretToken = null): Telegraph { return TelegraphFacade::bot($this)->registerWebhook($dropPendingUpdates, $maxConnections, $secretToken); } @@ -167,7 +168,7 @@ public function getFileInfo(string $fileId): Telegraph return TelegraphFacade::bot($this)->getFileInfo($fileId); } - public function store(Downloadable|string $attachment, string $path, string $filename = null): string + public function store(Downloadable|string $attachment, string $path, string|null $filename = null): string { return TelegraphFacade::bot($this)->store($attachment, $path, $filename); } @@ -182,7 +183,7 @@ public function url(): string * * @return \Illuminate\Support\Collection */ - public function updates(int $timeout = null, int $offset = null, int $limit = null, array $allowedUpdates = null): \Illuminate\Support\Collection + public function updates(int|null $timeout = null, int|null $offset = null, int|null $limit = null, array|null $allowedUpdates = null): \Illuminate\Support\Collection { $reply = TelegraphFacade::bot($this)->botUpdates($timeout, $offset, $limit, $allowedUpdates)->send(); diff --git a/src/Models/TelegraphChat.php b/src/Models/TelegraphChat.php index f5ffe065e..054045018 100644 --- a/src/Models/TelegraphChat.php +++ b/src/Models/TelegraphChat.php @@ -35,6 +35,7 @@ */ class TelegraphChat extends Model implements Storable { + /** @use HasFactory */ use HasFactory; use HasStorage; @@ -219,7 +220,7 @@ public function action(string $action): Telegraph return TelegraphFacade::chat($this)->chatAction($action); } - public function document(string $path, string $filename = null): Telegraph + public function document(string $path, string|null $filename = null): Telegraph { return TelegraphFacade::chat($this)->document($path, $filename); } @@ -229,7 +230,7 @@ public function location(float $latitude, float $longitude): Telegraph return TelegraphFacade::chat($this)->location(latitude: $latitude, longitude: $longitude); } - public function photo(string $path, string $filename = null): Telegraph + public function photo(string $path, string|null $filename = null): Telegraph { return TelegraphFacade::chat($this)->photo($path, $filename); } @@ -242,7 +243,7 @@ public function mediaGroup(array $media): Telegraph return TelegraphFacade::chat($this)->mediaGroup($media); } - public function sticker(string $path, string $filename = null): Telegraph + public function sticker(string $path, string|null $filename = null): Telegraph { return TelegraphFacade::chat($this)->sticker($path, $filename); } @@ -252,22 +253,22 @@ public function venue(float $latitude, float $longitude, string $title, string $ return TelegraphFacade::chat($this)->venue($latitude, $longitude, $title, $address); } - public function animation(string $path, string $filename = null): Telegraph + public function animation(string $path, string|null $filename = null): Telegraph { return TelegraphFacade::chat($this)->animation($path, $filename); } - public function video(string $path, string $filename = null): Telegraph + public function video(string $path, string|null $filename = null): Telegraph { return TelegraphFacade::chat($this)->video($path, $filename); } - public function audio(string $path, string $filename = null): Telegraph + public function audio(string $path, string|null $filename = null): Telegraph { return TelegraphFacade::chat($this)->audio($path, $filename); } - public function voice(string $path, string $filename = null): Telegraph + public function voice(string $path, string|null $filename = null): Telegraph { return TelegraphFacade::chat($this)->voice($path, $filename); } @@ -403,7 +404,7 @@ public function quiz(string $question): TelegraphQuizPayload return TelegraphFacade::chat($this)->quiz($question); } - public function dice(string $emoji = null): Telegraph + public function dice(string|null $emoji = null): Telegraph { return TelegraphFacade::chat($this)->dice($emoji); } @@ -423,27 +424,27 @@ public function setMenuButton(): SetChatMenuButtonPayload return TelegraphFacade::chat($this)->setChatMenuButton(); } - public function createForumTopic(string $name, int $iconColor = null, string $iconCustomEmojiId = null): Telegraph + public function createForumTopic(string $name, int|null $iconColor = null, string|null $iconCustomEmojiId = null): Telegraph { return TelegraphFacade::chat($this)->createForumTopic($name, $iconColor, $iconCustomEmojiId); } - public function editForumTopic(int $threadId = null, string $name = null, string $iconCustomEmojiId = null): Telegraph + public function editForumTopic(int|null $threadId = null, string|null $name = null, string|null $iconCustomEmojiId = null): Telegraph { return TelegraphFacade::chat($this)->editForumTopic($threadId, $name, $iconCustomEmojiId); } - public function closeForumTopic(int $threadId = null): Telegraph + public function closeForumTopic(int|null $threadId = null): Telegraph { return TelegraphFacade::chat($this)->closeForumTopic($threadId); } - public function reopenForumTopic(int $threadId = null): Telegraph + public function reopenForumTopic(int|null $threadId = null): Telegraph { return TelegraphFacade::chat($this)->reopenForumTopic($threadId); } - public function deleteForumTopic(int $threadId = null): Telegraph + public function deleteForumTopic(int|null $threadId = null): Telegraph { return TelegraphFacade::chat($this)->deleteForumTopic($threadId); } diff --git a/src/ScopedPayloads/TelegraphEditMediaPayload.php b/src/ScopedPayloads/TelegraphEditMediaPayload.php index 90c0aff0f..036dc8f42 100644 --- a/src/ScopedPayloads/TelegraphEditMediaPayload.php +++ b/src/ScopedPayloads/TelegraphEditMediaPayload.php @@ -10,7 +10,7 @@ class TelegraphEditMediaPayload extends \DefStudio\Telegraph\Telegraph { use BuildsFromTelegraphClass; - public function photo(string $path, string $filename = null): self + public function photo(string $path, string|null $filename = null): self { $telegraph = clone $this; @@ -29,7 +29,7 @@ public function photo(string $path, string $filename = null): self return $telegraph; } - public function document(string $path, string $filename = null): self + public function document(string $path, string|null $filename = null): self { $telegraph = clone $this; @@ -48,7 +48,7 @@ public function document(string $path, string $filename = null): self return $telegraph; } - public function animation(string $path, string $filename = null): self + public function animation(string $path, string|null $filename = null): self { $telegraph = clone $this; @@ -67,7 +67,7 @@ public function animation(string $path, string $filename = null): self return $telegraph; } - public function video(string $path, string $filename = null): self + public function video(string $path, string|null $filename = null): self { $telegraph = clone $this; @@ -86,7 +86,7 @@ public function video(string $path, string $filename = null): self return $telegraph; } - public function audio(string $path, string $filename = null): self + public function audio(string $path, string|null $filename = null): self { $telegraph = clone $this; diff --git a/tests/Unit/Concerns/HasBotsAndChatsTest.php b/tests/Unit/Concerns/HasBotsAndChatsTest.php index 606d68bf2..314ff55e7 100644 --- a/tests/Unit/Concerns/HasBotsAndChatsTest.php +++ b/tests/Unit/Concerns/HasBotsAndChatsTest.php @@ -123,31 +123,31 @@ })->toMatchUtf8TelegramSnapshot(); }); -test('photo is validated', function (string $path, bool $valid, string $exceptionClass = null, string $exceptionMessage = null, array $customConfigs = []) { +test('photo is validated', function (string $fileName, bool $valid, string $exceptionClass = null, string $exceptionMessage = null, array $customConfigs = []) { foreach ($customConfigs as $key => $value) { Config::set($key, $value); } if ($valid) { - expect(make_chat()->setChatPhoto(Storage::path($path))) + expect(make_chat()->setChatPhoto(Storage::path($fileName))) ->toBeInstanceOf(\DefStudio\Telegraph\Telegraph::class); } else { - expect(fn () => make_chat()->photo(Storage::path($path))) + expect(fn () => make_chat()->photo(Storage::path($fileName))) ->toThrow($exceptionClass, $exceptionMessage); } })->with([ 'valid' => [ - 'file' => 'photo.jpg', + 'fileName' => 'photo.jpg', 'valid' => true, ], 'invalid weight' => [ - 'file' => 'invalid_photo_size.jpg', + 'fileName' => 'invalid_photo_size.jpg', 'valid' => false, 'exception' => FileException::class, 'message' => 'Photo size (10.340000 Mb) exceeds max allowed size of 10.000000 MB', ], 'valid custom weight' => [ - 'file' => 'invalid_photo_size.jpg', + 'fileName' => 'invalid_photo_size.jpg', 'valid' => true, 'exception' => null, 'message' => null, @@ -156,7 +156,7 @@ ], ], 'invalid custom weight' => [ - 'file' => 'photo.jpg', + 'fileName' => 'photo.jpg', 'valid' => false, 'exception' => FileException::class, 'message' => 'Photo size (0.030000 Mb) exceeds max allowed size of 0.010000 MB', @@ -165,13 +165,13 @@ ], ], 'invalid ratio' => [ - 'file' => 'invalid_photo_ratio_thin.jpg', + 'fileName' => 'invalid_photo_ratio_thin.jpg', 'valid' => false, 'exception' => FileException::class, 'message' => "Ratio of height and width (22.222222) exceeds max allowed ratio of 20.000000", ], 'valid custom ratio' => [ - 'file' => 'invalid_photo_ratio_thin.jpg', + 'fileName' => 'invalid_photo_ratio_thin.jpg', 'valid' => true, 'exception' => null, 'message' => null, @@ -180,7 +180,7 @@ ], ], 'invalid custom ratio' => [ - 'file' => 'photo.jpg', + 'fileName' => 'photo.jpg', 'valid' => false, 'exception' => FileException::class, 'message' => "Ratio of height and width (1.000000) exceeds max allowed ratio of 0.990000", @@ -189,13 +189,13 @@ ], ], 'invalid size' => [ - 'file' => 'invalid_photo_ratio_huge.jpg', + 'fileName' => 'invalid_photo_ratio_huge.jpg', 'valid' => false, 'exception' => FileException::class, 'message' => 'Photo\'s sum of width and height (11000px) exceed allowed 10000px', ], 'valid custom size' => [ - 'file' => 'invalid_photo_ratio_huge.jpg', + 'fileName' => 'invalid_photo_ratio_huge.jpg', 'valid' => true, 'exception' => null, 'message' => null, @@ -204,7 +204,7 @@ ], ], 'invalid custom size' => [ - 'file' => 'photo.jpg', + 'fileName' => 'photo.jpg', 'valid' => false, 'exception' => FileException::class, 'message' => 'Photo\'s sum of width and height (800px) exceed allowed 799px', diff --git a/tests/Unit/Storage/FileStoreDriverTest.php b/tests/Unit/Storage/FileStoreDriverTest.php index 6a4b75e27..136e577ac 100644 --- a/tests/Unit/Storage/FileStoreDriverTest.php +++ b/tests/Unit/Storage/FileStoreDriverTest.php @@ -2,6 +2,7 @@ use DefStudio\Telegraph\Models\TelegraphChat; use DefStudio\Telegraph\Tests\Unit\Storage\TestStorable; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; beforeEach(function () {