From dfb812237bb0b720fa0c8d77ceb32a8b676b2c25 Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 3 Oct 2024 21:14:27 -0400 Subject: [PATCH] Updated classes fromArray signatures (in-progress) --- .../Interfaces/ObjectTypeInterface.php | 6 ++-- src/TgBotLib/Objects/BackgroundFill.php | 7 ++++- .../BackgroundFillFreeformGradient.php | 7 ++++- .../BackgroundFill/BackgroundFillGradient.php | 7 ++++- .../BackgroundFill/BackgroundFillSolid.php | 8 +++-- src/TgBotLib/Objects/BackgroundType.php | 9 +++++- .../BackgroundTypeChatTheme.php | 8 +++-- .../BackgroundType/BackgroundTypeFill.php | 5 ++-- .../BackgroundType/BackgroundTypePattern.php | 8 +++-- .../BackgroundTypeWallpaper.php | 8 +++-- src/TgBotLib/Objects/BotCommandScope.php | 7 ++++- .../BotCommandScopeAllChatAdministrators.php | 16 +++++----- .../BotCommandScopeAllGroupChats.php | 7 ++++- .../BotCommandScopeAllPrivateChats.php | 7 ++++- .../BotCommandScope/BotCommandScopeChat.php | 7 ++++- .../BotCommandScopeChatAdministrators.php | 7 ++++- .../BotCommandScopeChatMember.php | 7 ++++- .../BotCommandScopeDefault.php | 7 ++++- src/TgBotLib/Objects/ChatMember.php | 7 ++++- .../ChatMember/ChatMemberAdministrator.php | 7 ++++- .../Objects/ChatMember/ChatMemberBanned.php | 7 ++++- .../Objects/ChatMember/ChatMemberLeft.php | 7 ++++- .../Objects/ChatMember/ChatMemberMember.php | 7 ++++- .../Objects/ChatMember/ChatMemberOwner.php | 7 ++++- .../ChatMember/ChatMemberRestricted.php | 9 ++++-- .../Objects/Inline/ChosenInlineResult.php | 12 +++++--- .../Objects/Inline/InlineKeyboardButton.php | 12 +++++--- .../Objects/Inline/InlineKeyboardMarkup.php | 12 +++++--- src/TgBotLib/Objects/Inline/InlineQuery.php | 12 +++++--- .../Objects/Inline/InlineQueryResult.php | 30 +++++++++++++++++-- .../InlineQueryResultArticle.php | 7 ++++- .../InlineQueryResultAudio.php | 7 ++++- .../InlineQueryResultContact.php | 7 ++++- .../InlineQueryResultDocument.php | 7 ++++- .../InlineQueryResultGame.php | 7 ++++- .../InlineQueryResultGif.php | 7 ++++- .../InlineQueryResultLocation.php | 7 ++++- .../InlineQueryResultMpeg4Gif.php | 7 ++++- .../InlineQueryResultPhoto.php | 7 ++++- .../InlineQueryResultVenue.php | 7 ++++- .../InlineQueryResultVideo.php | 7 ++++- .../InlineQueryResultVoice.php | 7 ++++- .../Objects/Inline/SentWebAppMessage.php | 12 +++++--- 43 files changed, 288 insertions(+), 75 deletions(-) diff --git a/src/TgBotLib/Interfaces/ObjectTypeInterface.php b/src/TgBotLib/Interfaces/ObjectTypeInterface.php index 10e6ee1..221204d 100644 --- a/src/TgBotLib/Interfaces/ObjectTypeInterface.php +++ b/src/TgBotLib/Interfaces/ObjectTypeInterface.php @@ -14,8 +14,8 @@ /** * Reconstruction of the object from an array * - * @param array $data - * @return ObjectTypeInterface + * @param array|null $data + * @return ObjectTypeInterface|null */ - public static function fromArray(array $data): ObjectTypeInterface; + public static function fromArray(?array $data): ?ObjectTypeInterface; } \ No newline at end of file diff --git a/src/TgBotLib/Objects/BackgroundFill.php b/src/TgBotLib/Objects/BackgroundFill.php index 1148946..00d8506 100644 --- a/src/TgBotLib/Objects/BackgroundFill.php +++ b/src/TgBotLib/Objects/BackgroundFill.php @@ -31,8 +31,13 @@ abstract class BackgroundFill implements ObjectTypeInterface /** * @inheritDoc */ - public static function fromArray(array $data): BackgroundFill + public static function fromArray(?array $data): ?BackgroundFill { + if($data === null) + { + return null; + } + if(!isset($data['type'])) { throw new InvalidArgumentException('BackgroundFill expected type'); diff --git a/src/TgBotLib/Objects/BackgroundFill/BackgroundFillFreeformGradient.php b/src/TgBotLib/Objects/BackgroundFill/BackgroundFillFreeformGradient.php index b160c4a..417ba1c 100644 --- a/src/TgBotLib/Objects/BackgroundFill/BackgroundFillFreeformGradient.php +++ b/src/TgBotLib/Objects/BackgroundFill/BackgroundFillFreeformGradient.php @@ -37,8 +37,13 @@ class BackgroundFillFreeformGradient extends BackgroundFill implements ObjectTyp /** * @inheritDoc */ - public static function fromArray(array $data): BackgroundFill + public static function fromArray(?array $data): ?BackgroundFillFreeformGradient { + if($data === null) + { + return null; + } + $object = new self(); $object->type = BackgroundFillType::FREEFORM_GRADIENT; diff --git a/src/TgBotLib/Objects/BackgroundFill/BackgroundFillGradient.php b/src/TgBotLib/Objects/BackgroundFill/BackgroundFillGradient.php index 47e9393..5bd82c7 100644 --- a/src/TgBotLib/Objects/BackgroundFill/BackgroundFillGradient.php +++ b/src/TgBotLib/Objects/BackgroundFill/BackgroundFillGradient.php @@ -57,8 +57,13 @@ class BackgroundFillGradient extends BackgroundFill implements ObjectTypeInterfa /** * @inheritDoc */ - public static function fromArray(array $data): BackgroundFillGradient + public static function fromArray(?array $data): ?BackgroundFillGradient { + if($data === null) + { + return null; + } + $object = new self(); $object->type = $data['type'] ?? null; $object->top_color = $data['top_color'] ?? 0; diff --git a/src/TgBotLib/Objects/BackgroundFill/BackgroundFillSolid.php b/src/TgBotLib/Objects/BackgroundFill/BackgroundFillSolid.php index e0b138d..0100bdb 100644 --- a/src/TgBotLib/Objects/BackgroundFill/BackgroundFillSolid.php +++ b/src/TgBotLib/Objects/BackgroundFill/BackgroundFillSolid.php @@ -34,10 +34,14 @@ class BackgroundFillSolid extends BackgroundFill implements ObjectTypeInterface /** * @inheritDoc */ - public static function fromArray(array $data): BackgroundFill + public static function fromArray(?array $data): ?BackgroundFillSolid { - $object = new self(); + if($data === null) + { + return null; + } + $object = new self(); $object->type = BackgroundFillType::SOLID; $object->color = $data['color']; diff --git a/src/TgBotLib/Objects/BackgroundType.php b/src/TgBotLib/Objects/BackgroundType.php index 04f2f3c..c367d90 100644 --- a/src/TgBotLib/Objects/BackgroundType.php +++ b/src/TgBotLib/Objects/BackgroundType.php @@ -7,6 +7,7 @@ use TgBotLib\Enums\Types\BackgroundType as type; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\BackgroundType\BackgroundTypeChatTheme; use TgBotLib\Objects\BackgroundType\BackgroundTypeFill; +use TgBotLib\Objects\BackgroundType\BackgroundTypePattern; use TgBotLib\Objects\BackgroundType\BackgroundTypeWallpaper; abstract class BackgroundType implements ObjectTypeInterface @@ -31,8 +32,13 @@ abstract class BackgroundType implements ObjectTypeInterface /** * @inheritDoc */ - public static function fromArray(array $data): BackgroundType + public static function fromArray(?array $data): ?BackgroundType { + if($data === null) + { + return null; + } + if (!isset($data['type'])) { throw new InvalidArgumentException('BackgroundType expected type'); @@ -42,6 +48,7 @@ abstract class BackgroundType implements ObjectTypeInterface { type::WALLPAPER => BackgroundTypeWallpaper::fromArray($data), type::FILL => BackgroundTypeFill::fromArray($data), + type::PATTERN => BackgroundTypePattern::fromArray($data), type::CHAT_THEME => BackgroundTypeChatTheme::fromArray($data), default => throw new InvalidArgumentException("Invalid BackgroundType Type") }; diff --git a/src/TgBotLib/Objects/BackgroundType/BackgroundTypeChatTheme.php b/src/TgBotLib/Objects/BackgroundType/BackgroundTypeChatTheme.php index 1ce4a4b..a1fce8b 100644 --- a/src/TgBotLib/Objects/BackgroundType/BackgroundTypeChatTheme.php +++ b/src/TgBotLib/Objects/BackgroundType/BackgroundTypeChatTheme.php @@ -34,10 +34,14 @@ class BackgroundTypeChatTheme extends BackgroundType implements ObjectTypeInterf /** * @inheritDoc */ - public static function fromArray(array $data): BackgroundTypeChatTheme + public static function fromArray(?array $data): ?BackgroundTypeChatTheme { - $object = new self(); + if($data === null) + { + return null; + } + $object = new self(); $object->type = type::CHAT_THEME; $object->theme_name = $data['theme_name']; diff --git a/src/TgBotLib/Objects/BackgroundType/BackgroundTypeFill.php b/src/TgBotLib/Objects/BackgroundType/BackgroundTypeFill.php index 2d3c8f3..d7ac603 100644 --- a/src/TgBotLib/Objects/BackgroundType/BackgroundTypeFill.php +++ b/src/TgBotLib/Objects/BackgroundType/BackgroundTypeFill.php @@ -47,10 +47,11 @@ class BackgroundTypeFill extends BackgroundType implements ObjectTypeInterface /** * @inheritDoc */ - public static function fromArray(array $data): BackgroundTypeFill + public static function fromArray(?array $data): ?BackgroundTypeFill { - $object = new self(); + if() + $object = new self(); $object->type = type::FILL; $object->fill = BackgroundFill::fromArray($data['fill']); $object->dark_theme_dimming = $data['dark_theme_dimming']; diff --git a/src/TgBotLib/Objects/BackgroundType/BackgroundTypePattern.php b/src/TgBotLib/Objects/BackgroundType/BackgroundTypePattern.php index 9631159..e09b5f9 100644 --- a/src/TgBotLib/Objects/BackgroundType/BackgroundTypePattern.php +++ b/src/TgBotLib/Objects/BackgroundType/BackgroundTypePattern.php @@ -85,10 +85,14 @@ class BackgroundTypePattern extends BackgroundType implements ObjectTypeInterfac /** * @inheritDoc */ - public static function fromArray(array $data): BackgroundTypePattern + public static function fromArray(?array $data): ?BackgroundTypePattern { - $object = new self(); + if($data === null) + { + return null; + } + $object = new self(); $object->type = type::PATTERN; $object->document = Document::fromArray($data['document']); $object->fill = BackgroundFill::fromArray($data['fill']); diff --git a/src/TgBotLib/Objects/BackgroundType/BackgroundTypeWallpaper.php b/src/TgBotLib/Objects/BackgroundType/BackgroundTypeWallpaper.php index d3c13a8..71ada43 100644 --- a/src/TgBotLib/Objects/BackgroundType/BackgroundTypeWallpaper.php +++ b/src/TgBotLib/Objects/BackgroundType/BackgroundTypeWallpaper.php @@ -71,10 +71,14 @@ class BackgroundTypeWallpaper extends BackgroundType implements ObjectTypeInterf /** * @inheritDoc */ - public static function fromArray(array $data): BackgroundTypeWallpaper + public static function fromArray(?array $data): ?BackgroundTypeWallpaper { - $object = new self(); + if($data === null) + { + return null; + } + $object = new self(); $object->type = type::WALLPAPER; $object->document = Document::fromArray($data['document']); $object->dark_theme_dimming = $data['dark_theme_dimming']; diff --git a/src/TgBotLib/Objects/BotCommandScope.php b/src/TgBotLib/Objects/BotCommandScope.php index 7b4fc48..3d87ca8 100644 --- a/src/TgBotLib/Objects/BotCommandScope.php +++ b/src/TgBotLib/Objects/BotCommandScope.php @@ -41,8 +41,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): ObjectTypeInterface + public static function fromArray(?array $data): ?BotCommandScope { + if($data === null) + { + return null; + } + if(!isset($data['type'])) { throw new InvalidArgumentException('BotCommandScope expected type'); diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllChatAdministrators.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllChatAdministrators.php index 8280dcf..f9e143c 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllChatAdministrators.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllChatAdministrators.php @@ -26,9 +26,7 @@ } /** - * Returns an array representation of the object - * - * @return array + * @inheritDoc */ public function toArray(): array { @@ -39,13 +37,15 @@ } /** - * Constructs object from an array representation - * - * @param array $data - * @return BotCommandScopeAllChatAdministrators + * @inheritDoc */ - public static function fromArray(array $data): BotCommandScopeAllChatAdministrators + public static function fromArray(?array $data): ?BotCommandScopeAllChatAdministrators { + if($data === null) + { + return null; + } + $object = new self(); $object->type = BotCommandScopeType::ALL_CHAT_ADMINISTRATORS; $object->chat_id = $data['chat_id'] ?? null; diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllGroupChats.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllGroupChats.php index cf759d4..98248cd 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllGroupChats.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllGroupChats.php @@ -23,8 +23,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): self + public static function fromArray(?array $data): ?BotCommandScopeAllGroupChats { + if($data === null) + { + return null; + } + $object = new self(); $object->type = BotCommandScopeType::ALL_CHAT_GROUPS; diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllPrivateChats.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllPrivateChats.php index b383bfc..996eccf 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllPrivateChats.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllPrivateChats.php @@ -23,8 +23,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): BotCommandScopeAllPrivateChats + public static function fromArray(?array $data): ?BotCommandScopeAllPrivateChats { + if($data === null) + { + return null; + } + $object = new self(); $object->type = BotCommandScopeType::ALL_PRIVATE_CHATS; diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChat.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChat.php index 2cbb929..967c9d0 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChat.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChat.php @@ -39,8 +39,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): self + public static function fromArray(?array $data): ?BotCommandScopeChat { + if($data === null) + { + return null; + } + $object = new self(); $object->type = BotCommandScopeType::CHAT; $object->chat_id = $data['chat_id'] ?? null; diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatAdministrators.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatAdministrators.php index dbb678a..1cc15dc 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatAdministrators.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatAdministrators.php @@ -24,8 +24,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): self + public static function fromArray(?array $data): ?BotCommandScopeChatAdministrators { + if($data === null) + { + return null; + } + $object = new self(); $object->type = BotCommandScopeType::CHAT_ADMINISTRATORS; diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatMember.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatMember.php index c95f40d..bfe662a 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatMember.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatMember.php @@ -48,8 +48,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): self + public static function fromArray(?array $data): ?BotCommandScopeChatMember { + if($data === null) + { + return null; + } + $object = new self(); $object->type = BotCommandScopeType::CHAT_MEMBER; $object->chat_id = $data['chat_id'] ?? null; diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeDefault.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeDefault.php index 9ffe53e..8cff1a9 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeDefault.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeDefault.php @@ -23,8 +23,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): BotCommandScopeDefault + public static function fromArray(?array $data): ?BotCommandScopeDefault { + if($data === null) + { + return null; + } + $object = new self(); $object->type = BotCommandScopeType::DEFAULT; diff --git a/src/TgBotLib/Objects/ChatMember.php b/src/TgBotLib/Objects/ChatMember.php index 6fa8921..59308f2 100644 --- a/src/TgBotLib/Objects/ChatMember.php +++ b/src/TgBotLib/Objects/ChatMember.php @@ -39,8 +39,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): ChatMember + public static function fromArray(?array $data): ?ChatMember { + if($data === null) + { + return null; + } + if(!isset($data['status'])) { throw new InvalidArgumentException('ChatMember expected status'); diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberAdministrator.php b/src/TgBotLib/Objects/ChatMember/ChatMemberAdministrator.php index 00e18b7..1134c80 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberAdministrator.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberAdministrator.php @@ -210,8 +210,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): ChatMemberAdministrator + public static function fromArray(?array $data): ?ChatMemberAdministrator { + if($data === null) + { + return null; + } + $object = new self(); $object->status = ChatMemberStatus::ADMINISTRATOR; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberBanned.php b/src/TgBotLib/Objects/ChatMember/ChatMemberBanned.php index 8fd2a6f..f23b68a 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberBanned.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberBanned.php @@ -49,8 +49,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): ChatMemberBanned + public static function fromArray(?array $data): ?ChatMemberBanned { + if($data === null) + { + return null; + } + $object = new self(); $object->status = ChatMemberStatus::KICKED; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberLeft.php b/src/TgBotLib/Objects/ChatMember/ChatMemberLeft.php index cec1c65..fab7c44 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberLeft.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberLeft.php @@ -37,8 +37,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): ChatMemberLeft + public static function fromArray(?array $data): ?ChatMemberLeft { + if($data === null) + { + return null; + } + $object = new self(); $object->status = ChatMemberStatus::LEFT; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberMember.php b/src/TgBotLib/Objects/ChatMember/ChatMemberMember.php index 8628497..7e58e46 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberMember.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberMember.php @@ -37,8 +37,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): ChatMemberMember + public static function fromArray(?array $data): ?ChatMemberMember { + if($data === null) + { + return null; + } + $object = new self(); $object->status = ChatMemberStatus::MEMBER; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberOwner.php b/src/TgBotLib/Objects/ChatMember/ChatMemberOwner.php index ce11f96..4f31a85 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberOwner.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberOwner.php @@ -61,8 +61,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): ChatMemberOwner + public static function fromArray(?array $data): ?ChatMemberOwner { + if($data === null) + { + return null; + } + $object = new ChatMemberOwner(); $object->status = ChatMemberStatus::CREATOR; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberRestricted.php b/src/TgBotLib/Objects/ChatMember/ChatMemberRestricted.php index 27f9bee..270b884 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberRestricted.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberRestricted.php @@ -229,9 +229,14 @@ /** * @inheritDoc */ - public static function fromArray(array $data): ChatMemberRestricted + public static function fromArray(?array $data): ?ChatMemberRestricted { - $object = new static(); + if($data === null) + { + return null; + } + + $object = new self(); $object->status = ChatMemberStatus::RESTRICTED; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->is_member = $data['is_member'] ?? false; diff --git a/src/TgBotLib/Objects/Inline/ChosenInlineResult.php b/src/TgBotLib/Objects/Inline/ChosenInlineResult.php index f5ae9f2..75e81cb 100644 --- a/src/TgBotLib/Objects/Inline/ChosenInlineResult.php +++ b/src/TgBotLib/Objects/Inline/ChosenInlineResult.php @@ -108,13 +108,17 @@ /** * Constructs object from an array representation * - * @param array $data - * @return ChosenInlineResult + * @param array|null $data + * @return ChosenInlineResult|null */ - public static function fromArray(array $data): self + public static function fromArray(?array $data): ?ChosenInlineResult { - $object = new self(); + if($data === null) + { + return null; + } + $object = new self(); $object->result_id = $data['result_id'] ?? null; $object->from = $data['from'] ?? null; $object->location = $data['location'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineKeyboardButton.php b/src/TgBotLib/Objects/Inline/InlineKeyboardButton.php index 517f04e..9008282 100644 --- a/src/TgBotLib/Objects/Inline/InlineKeyboardButton.php +++ b/src/TgBotLib/Objects/Inline/InlineKeyboardButton.php @@ -334,13 +334,17 @@ /** * Constructs a new InlineKeyboardButton object from an array * - * @param array $data - * @return InlineKeyboardButton + * @param array|null $data + * @return InlineKeyboardButton|null */ - public static function fromArray(array $data): self + public static function fromArray(?array $data): ?InlineKeyboardButton { - $object = new self(); + if($data === null) + { + return null; + } + $object = new self(); $object->text = $data['text'] ?? null; $object->url = $data['url'] ?? null; $object->callback_data = $data['callback_data'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineKeyboardMarkup.php b/src/TgBotLib/Objects/Inline/InlineKeyboardMarkup.php index e0bd3c7..19c6757 100644 --- a/src/TgBotLib/Objects/Inline/InlineKeyboardMarkup.php +++ b/src/TgBotLib/Objects/Inline/InlineKeyboardMarkup.php @@ -72,13 +72,17 @@ /** * Constructs the object from an array representation * - * @param array $data - * @return InlineKeyboardMarkup + * @param array|null $data + * @return InlineKeyboardMarkup|null */ - public static function fromArray(array $data): self + public static function fromArray(?array $data): ?InlineKeyboardMarkup { - $object = new self(); + if($data === null) + { + return null; + } + $object = new self(); $object->inline_keyboard = []; foreach($data as $item) diff --git a/src/TgBotLib/Objects/Inline/InlineQuery.php b/src/TgBotLib/Objects/Inline/InlineQuery.php index 950ecb7..3376efd 100644 --- a/src/TgBotLib/Objects/Inline/InlineQuery.php +++ b/src/TgBotLib/Objects/Inline/InlineQuery.php @@ -123,13 +123,17 @@ /** * Constructs object from an array representation * - * @param array $data - * @return InlineQuery + * @param array|null $data + * @return InlineQuery|null */ - public static function fromArray(array $data): self + public static function fromArray(?array $data): ?InlineQuery { - $object = new self(); + if($data === null) + { + return null; + } + $object = new self(); $object->id = $data['id']; $object->from = isset($data['from']) && is_array($data['from']) ? User::fromArray($data['from']) : $data['from']; $object->query = $data['query']; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult.php b/src/TgBotLib/Objects/Inline/InlineQueryResult.php index 5d7d350..78cef37 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult.php @@ -5,7 +5,6 @@ use InvalidArgumentException; use TgBotLib\Classes\Validate; use TgBotLib\Enums\Types\InlineQueryResultType; - use TgBotLib\Exceptions\NotImplementedException; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultArticle; use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultAudio; @@ -71,8 +70,33 @@ /** * @inheritDoc */ - public static function fromArray(array $data): ObjectTypeInterface + public static function fromArray(?array $data): ?InlineQueryResult { - // TODO: Implement this + if($data === null) + { + return null; + } + + if(!isset($data['type'])) + { + throw new InvalidArgumentException('InlineQueryResult expected type'); + } + + return match(InlineQueryResultType::tryFrom($data['type'])) + { + InlineQueryResultType::ARTICLE => InlineQueryResultArticle::fromArray($data), + InlineQueryResultType::AUDIO => InlineQueryResultAudio::fromArray($data), + InlineQueryResultType::CONTACT => InlineQueryResultContact::fromArray($data), + InlineQueryResultType::DOCUMENT => InlineQueryResultDocument::fromArray($data), + InlineQueryResultType::GAME => InlineQueryResultGame::fromArray($data), + InlineQueryResultType::GIF => InlineQueryResultGif::fromArray($data), + InlineQueryResultType::LOCATION => InlineQueryResultLocation::fromArray($data), + InlineQueryResultType::MPEG_4_GIF => InlineQueryResultMpeg4Gif::fromArray($data), + InlineQueryResultType::PHOTO => InlineQueryResultPhoto::fromArray($data), + InlineQueryResultType::VENUE => InlineQueryResultVenue::fromArray($data), + InlineQueryResultType::VIDEO => InlineQueryResultVideo::fromArray($data), + InlineQueryResultType::VOICE => InlineQueryResultVoice::fromArray($data), + default => throw new InvalidArgumentException('Unexpected type for InlineQueryResult') + }; } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultArticle.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultArticle.php index 90e5584..b04d1d7 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultArticle.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultArticle.php @@ -262,8 +262,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultArticle + public static function fromArray(?array $data): ?InlineQueryResultArticle { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::ARTICLE; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultAudio.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultAudio.php index c668023..9ae495e 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultAudio.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultAudio.php @@ -312,8 +312,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultAudio + public static function fromArray(?array $data): ?InlineQueryResultAudio { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::AUDIO; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultContact.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultContact.php index 7cefc2a..2d5dd02 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultContact.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultContact.php @@ -260,8 +260,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultContact + public static function fromArray(?array $data): ?InlineQueryResultContact { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::CONTACT; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultDocument.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultDocument.php index 8000e04..c784297 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultDocument.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultDocument.php @@ -381,8 +381,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultDocument + public static function fromArray(?array $data): ?InlineQueryResultDocument { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::DOCUMENT; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultGame.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultGame.php index 27f57b7..7c90cb3 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultGame.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultGame.php @@ -89,8 +89,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultGame + public static function fromArray(?array $data): ?InlineQueryResultGame { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::GAME; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultGif.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultGif.php index 41e7029..f364edd 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultGif.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultGif.php @@ -390,8 +390,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultGif + public static function fromArray(?array $data): ?InlineQueryResultGif { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::GIF; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultLocation.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultLocation.php index c3b7812..d9615af 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultLocation.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultLocation.php @@ -339,8 +339,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultLocation + public static function fromArray(?array $data): ?InlineQueryResultLocation { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::LOCATION; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultMpeg4Gif.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultMpeg4Gif.php index 84ad592..c13c48c 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultMpeg4Gif.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultMpeg4Gif.php @@ -322,8 +322,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultMpeg4Gif + public static function fromArray(?array $data): ?InlineQueryResultMpeg4Gif { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::MPEG_4_GIF; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultPhoto.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultPhoto.php index 4164dfc..8e7ee40 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultPhoto.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultPhoto.php @@ -303,8 +303,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultPhoto + public static function fromArray(?array $data): ?InlineQueryResultPhoto { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::PHOTO; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVenue.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVenue.php index 865bd9e..d156c58 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVenue.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVenue.php @@ -342,8 +342,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultVenue + public static function fromArray(?array $data): ?InlineQueryResultVenue { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::VENUE; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVideo.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVideo.php index 70c3a90..aefb8d1 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVideo.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVideo.php @@ -356,8 +356,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): ObjectTypeInterface + public static function fromArray(?array $data): ?InlineQueryResultVideo { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::VIDEO; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVoice.php b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVoice.php index d5f5647..f8b972a 100644 --- a/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVoice.php +++ b/src/TgBotLib/Objects/Inline/InlineQueryResult/InlineQueryResultVoice.php @@ -232,8 +232,13 @@ /** * @inheritDoc */ - public static function fromArray(array $data): InlineQueryResultVoice + public static function fromArray(?array $data): ?InlineQueryResultVoice { + if($data === null) + { + return null; + } + $object = new self(); $object->type = InlineQueryResultType::VOICE; $object->id = $data['id'] ?? null; diff --git a/src/TgBotLib/Objects/Inline/SentWebAppMessage.php b/src/TgBotLib/Objects/Inline/SentWebAppMessage.php index b054b16..05b56f5 100644 --- a/src/TgBotLib/Objects/Inline/SentWebAppMessage.php +++ b/src/TgBotLib/Objects/Inline/SentWebAppMessage.php @@ -37,13 +37,17 @@ /** * Constructs object from an array representation * - * @param array $data - * @return SentWebAppMessage + * @param array|null $data + * @return SentWebAppMessage|null */ - public static function fromArray(array $data): SentWebAppMessage + public static function fromArray(?array $data): ?SentWebAppMessage { - $object = new self(); + if($data === null) + { + return null; + } + $object = new self(); $object->inline_message_id = $data['inline_message_id'] ?? null; return $object;