Skip to content

Commit

Permalink
improves types
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-ivona committed Aug 26, 2024
1 parent 9aae359 commit 9af9435
Show file tree
Hide file tree
Showing 27 changed files with 97 additions and 7 deletions.
3 changes: 3 additions & 0 deletions database/factories/TelegraphBotFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use DefStudio\Telegraph\Models\TelegraphBot;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends Factory<TelegraphBot>
*/
class TelegraphBotFactory extends Factory
{
protected $model = TelegraphBot::class;
Expand Down
3 changes: 3 additions & 0 deletions database/factories/TelegraphChatFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use DefStudio\Telegraph\Models\TelegraphChat;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends Factory<TelegraphChat>
*/
class TelegraphChatFactory extends Factory
{
protected $model = TelegraphChat::class;
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ parameters:
- '#expects string, array\|string\|null given#'
- '#expects string, mixed given#'


checkMissingIterableValueType: true
checkGenericClassInNonGenericObjectType: false
reportUnmatchedIgnoredErrors: false
7 changes: 5 additions & 2 deletions src/DTO/Animation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use DefStudio\Telegraph\Contracts\Downloadable;
use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|int|array<string, mixed>>
*/
class Animation implements Arrayable, Downloadable
{
private string $id;
Expand All @@ -26,8 +29,8 @@ private function __construct()
/**
* @param array{
* file_id: string,
* width: int,
* height: int,
* width: int,
* height: int,
* duration: int,
* file_name?: string,
* mime_type?: string,
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;

/**
* @implements Arrayable<string, string>
*/
class Attachment implements Arrayable
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use DefStudio\Telegraph\Contracts\Downloadable;
use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|int|array<string, mixed>>
*/
class Audio implements Arrayable, Downloadable
{
private string $id;
Expand Down
9 changes: 9 additions & 0 deletions src/DTO/CallbackQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

/**
* @implements Arrayable<string, string|int|array<string, mixed>>
*/
class CallbackQuery implements Arrayable
{
private int $id;
Expand All @@ -16,6 +19,9 @@ class CallbackQuery implements Arrayable

private Message|null $message = null;

/**
* @var Collection<string, string>
*/
private Collection $data;

private function __construct()
Expand Down Expand Up @@ -69,6 +75,9 @@ public function message(): Message|null
return $this->message;
}

/**
* @return Collection<string, string>
*/
public function data(): Collection
{
return $this->data;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string>
*/
class Chat implements Arrayable
{
public const TYPE_SENDER = 'sender';
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/ChatMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|int|bool|array<string, mixed>>
*/
class ChatMember implements Arrayable
{
public const STATUS_CREATOR = 'creator';
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/ChatMemberUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Carbon;

/**
* @implements Arrayable<string, string|int|array<string, mixed>>
*/
class ChatMemberUpdate implements Arrayable
{
private CarbonInterface $date;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|int>
*/
class Contact implements Arrayable
{
private string $phone_number;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use DefStudio\Telegraph\Contracts\Downloadable;
use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|int|array<string, mixed>>
*/
class Document implements Arrayable, Downloadable
{
private string $id;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/InlineQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|null|array<string, mixed>>
*/
class InlineQuery implements Arrayable
{
private string $id;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, float>
*/
class Location implements Arrayable
{
private float $latitude;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;

/**
* @implements Arrayable<string, string|int|bool|array<string, mixed>>
*/
class Message implements Arrayable
{
private int $id;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use DefStudio\Telegraph\Contracts\Downloadable;
use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|int>
*/
class Photo implements Arrayable, Downloadable
{
private string $id;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Sticker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use DefStudio\Telegraph\Contracts\Downloadable;
use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|int|bool|array<string, mixed>>
*/
class Sticker implements Arrayable, Downloadable
{
private string $id;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/TelegramUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, int|array<string, mixed>>
*/
class TelegramUpdate implements Arrayable
{
private int $id;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use DefStudio\Telegraph\Contracts\Storable;
use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|int|bool|array<string, mixed>>
*/
class User implements Arrayable, Storable
{
use HasStorage;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use DefStudio\Telegraph\Contracts\Downloadable;
use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|int|array<string, mixed>>
*/
class Video implements Arrayable, Downloadable
{
private string $id;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/Voice.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use DefStudio\Telegraph\Contracts\Downloadable;
use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|int>
*/
class Voice implements Arrayable, Downloadable
{
private string $id;
Expand Down
3 changes: 3 additions & 0 deletions src/DTO/WriteAccessAllowed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Contracts\Support\Arrayable;

/**
* @implements Arrayable<string, string|bool>
*/
class WriteAccessAllowed implements Arrayable
{
private bool $fromRequest = false;
Expand Down
3 changes: 3 additions & 0 deletions src/Handlers/WebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ abstract class WebhookHandler
protected Message|null $message = null;
protected CallbackQuery|null $callbackQuery = null;

/**
* @var Collection<string, string>
*/
protected Collection $data;

protected Keyboard $originalKeyboard;
Expand Down
3 changes: 3 additions & 0 deletions src/Keyboard/Keyboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Conditionable;

/**
* @implements Arrayable<string, array<array-key, array{text: string, url?: string, callback_data?: string, web_app?: string[], login_url?: string[], switch_inline_query?: string, switch_inline_query_current_chat?: string}>>
*/
class Keyboard implements Arrayable
{
use Conditionable;
Expand Down
7 changes: 5 additions & 2 deletions src/Keyboard/ReplyKeyboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\Conditionable;

/**
* @implements Arrayable<string, array<array-key, array{text: string, request_contact?: bool, request_location?: bool, request_poll?: string[], web_app?: string[]}>>
*/
class ReplyKeyboard implements Arrayable
{
use Conditionable;
Expand All @@ -25,7 +28,7 @@ class ReplyKeyboard implements Arrayable

public function __construct()
{
/* @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
$this->buttons = collect();
}

Expand Down Expand Up @@ -216,7 +219,7 @@ public function deleteButton(string $label): self
{
$clone = $this->clone();

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

return $clone;
Expand Down
8 changes: 7 additions & 1 deletion src/Models/TelegraphBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ class TelegraphBot extends Model implements Storable
'name',
];

/**
* @return TelegraphBotFactory
*/
protected static function newFactory(): Factory
{
return TelegraphBotFactory::new();
}

public static function booted()
public static function booted(): void
{
self::created(function (TelegraphBot $bot) {
if (empty($bot->name)) {
Expand Down Expand Up @@ -89,6 +92,9 @@ public static function fromToken(string $token): TelegraphBot
return self::query()->where('token', $token)->sole();
}

/**
* @return HasMany<TelegraphChat>
*/
public function chats(): HasMany
{
/** @phpstan-ignore-next-line */
Expand Down
8 changes: 7 additions & 1 deletion src/Models/TelegraphChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ class TelegraphChat extends Model implements Storable
'name',
];

/**
* @return TelegraphChatFactory
*/
protected static function newFactory(): Factory
{
return TelegraphChatFactory::new();
}

public static function booted()
public static function booted(): void
{
self::created(function (TelegraphChat $chat) {
if (empty($chat->name)) {
Expand All @@ -63,6 +66,9 @@ public function storageKey(): string|int
return $this->id;
}

/**
* @return BelongsTo<TelegraphBot, TelegraphChat>
*/
public function bot(): BelongsTo
{
/** @phpstan-ignore-next-line */
Expand Down

0 comments on commit 9af9435

Please sign in to comment.