From 54a8a59ee88f1c4bd88d8037c32d6a7e1800daab Mon Sep 17 00:00:00 2001 From: Netkas Date: Tue, 14 Feb 2023 17:35:16 -0500 Subject: [PATCH] Major Refactoring --- .idea/php.xml | 1 + .idea/tgbot.iml | 4 +- src/TgBotLib/Objects/Animation.php | 2 +- src/TgBotLib/Objects/Audio.php | 4 +- src/TgBotLib/Objects/BotCommand.php | 4 +- src/TgBotLib/Objects/BotCommandScope.php | 18 +- .../BotCommandScopeAllChatAdministrators.php | 11 +- .../BotCommandScopeAllGroupChats.php | 3 +- .../BotCommandScopeAllPrivateChats.php | 3 +- .../BotCommandScope/BotCommandScopeChat.php | 5 +- .../BotCommandScopeChatAdministrators.php | 3 +- .../BotCommandScopeChatMember.php | 9 +- .../BotCommandScopeDefault.php | 3 +- src/TgBotLib/Objects/CallbackQuery.php | 8 +- src/TgBotLib/Objects/Chat.php | 64 +-- .../Objects/ChatAdministratorRights.php | 25 +- src/TgBotLib/Objects/ChatInviteLink.php | 22 +- src/TgBotLib/Objects/ChatJoinRequest.php | 6 +- src/TgBotLib/Objects/ChatLocation.php | 4 +- src/TgBotLib/Objects/ChatMember.php | 105 ++--- .../ChatMember/ChatMemberAdministrator.php | 83 ++-- .../Objects/ChatMember/ChatMemberBanned.php | 7 +- .../Objects/ChatMember/ChatMemberLeft.php | 11 +- .../Objects/ChatMember/ChatMemberMember.php | 3 +- .../Objects/ChatMember/ChatMemberOwner.php | 8 +- .../ChatMember/ChatMemberRestricted.php | 96 ++--- src/TgBotLib/Objects/ChatMemberUpdated.php | 2 +- src/TgBotLib/Objects/ChatPermissions.php | 57 +-- src/TgBotLib/Objects/ChatPhoto.php | 10 +- src/TgBotLib/Objects/ChatShared.php | 4 +- src/TgBotLib/Objects/Contact.php | 10 +- src/TgBotLib/Objects/Dice.php | 4 +- src/TgBotLib/Objects/Document.php | 6 +- src/TgBotLib/Objects/EncryptedCredentials.php | 6 +- .../Objects/EncryptedPassportElement.php | 72 ++-- src/TgBotLib/Objects/File.php | 12 +- src/TgBotLib/Objects/ForceReply.php | 4 +- src/TgBotLib/Objects/ForumTopic.php | 8 +- src/TgBotLib/Objects/ForumTopicCreated.php | 9 +- src/TgBotLib/Objects/ForumTopicEdited.php | 4 +- src/TgBotLib/Objects/Game.php | 57 +-- src/TgBotLib/Objects/InlineKeyboardButton.php | 12 +- src/TgBotLib/Objects/InlineKeyboardMarkup.php | 26 +- src/TgBotLib/Objects/InputMedia.php | 57 +-- .../InputMedia/InputMediaAnimation.php | 60 ++- .../Objects/InputMedia/InputMediaAudio.php | 49 +-- .../Objects/InputMedia/InputMediaDocument.php | 41 +- .../Objects/InputMedia/InputMediaPhoto.php | 53 +-- .../Objects/InputMedia/InputMediaVideo.php | 61 ++- src/TgBotLib/Objects/Invoice.php | 10 +- src/TgBotLib/Objects/KeyboardButton.php | 14 +- .../Objects/KeyboardButtonPollType.php | 6 +- .../Objects/KeyboardButtonRequestChat.php | 26 +- .../Objects/KeyboardButtonRequestUser.php | 6 +- src/TgBotLib/Objects/LabeledPrice.php | 4 +- src/TgBotLib/Objects/Location.php | 12 +- src/TgBotLib/Objects/LoginUrl.php | 2 +- src/TgBotLib/Objects/MaskPosition.php | 8 +- src/TgBotLib/Objects/MenuButton.php | 4 +- .../Objects/MenuButton/MenuButtonCommands.php | 4 +- .../Objects/MenuButton/MenuButtonDefault.php | 2 +- .../Objects/MenuButton/MenuButtonWebApp.php | 12 +- src/TgBotLib/Objects/Message.php | 372 ++++++++---------- .../Objects/MessageAutoDeleteTimerChanged.php | 1 + src/TgBotLib/Objects/MessageEntity.php | 14 +- src/TgBotLib/Objects/PassportData.php | 8 +- src/TgBotLib/Objects/PassportFile.php | 8 +- src/TgBotLib/Objects/PhotoSize.php | 11 +- src/TgBotLib/Objects/PollAnswer.php | 6 +- src/TgBotLib/Objects/PollOption.php | 4 +- src/TgBotLib/Objects/PreCheckoutQuery.php | 16 +- .../Objects/ProximityAlertTriggered.php | 6 +- src/TgBotLib/Objects/ReplyKeyboardMarkup.php | 14 +- src/TgBotLib/Objects/ReplyKeyboardRemove.php | 4 +- src/TgBotLib/Objects/ShippingQuery.php | 8 +- src/TgBotLib/Objects/Sticker.php | 6 +- src/TgBotLib/Objects/SuccessfulPayment.php | 12 +- src/TgBotLib/Objects/User.php | 32 +- src/TgBotLib/Objects/Venue.php | 14 +- src/TgBotLib/Objects/Video.php | 2 +- src/TgBotLib/Objects/VideoNote.php | 12 +- src/TgBotLib/Objects/Voice.php | 10 +- src/TgBotLib/Objects/WebAppData.php | 4 +- 83 files changed, 892 insertions(+), 918 deletions(-) diff --git a/.idea/php.xml b/.idea/php.xml index 2c7445e..b2ca53c 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -9,6 +9,7 @@ + diff --git a/.idea/tgbot.iml b/.idea/tgbot.iml index c956989..77098d0 100644 --- a/.idea/tgbot.iml +++ b/.idea/tgbot.iml @@ -1,7 +1,9 @@ - + + + diff --git a/src/TgBotLib/Objects/Animation.php b/src/TgBotLib/Objects/Animation.php index 05a5a46..4a16139 100644 --- a/src/TgBotLib/Objects/Animation.php +++ b/src/TgBotLib/Objects/Animation.php @@ -159,7 +159,7 @@ 'width' => $this->width ?? null, 'height' => $this->height ?? null, 'duration' => $this->duration ?? null, - 'thumb' => ($this->thumb instanceof PhotoSize) ? $this->thumb->toArray() : null, + 'thumb' => ($this->thumb instanceof ObjectTypeInterface) ? $this->thumb->toArray() : null, 'file_name' => $this->file_name ?? null, 'mime_type' => $this->mime_type ?? null, 'file_size' => $this->file_size ?? null diff --git a/src/TgBotLib/Objects/Audio.php b/src/TgBotLib/Objects/Audio.php index 71d0c67..640f18d 100644 --- a/src/TgBotLib/Objects/Audio.php +++ b/src/TgBotLib/Objects/Audio.php @@ -1,5 +1,7 @@ $this->file_name ?? null, 'mime_type' => $this->mime_type ?? null, 'file_size' => $this->file_size ?? null, - 'thumb' => ($this->thumb instanceof PhotoSize) ? $this->thumb->toArray() : null, + 'thumb' => ($this->thumb instanceof ObjectTypeInterface) ? $this->thumb->toArray() : null, ]; } diff --git a/src/TgBotLib/Objects/BotCommand.php b/src/TgBotLib/Objects/BotCommand.php index 27c6b21..28c78cb 100644 --- a/src/TgBotLib/Objects/BotCommand.php +++ b/src/TgBotLib/Objects/BotCommand.php @@ -61,8 +61,8 @@ { $object = new self(); - $object->command = $data['command']; - $object->description = $data['description']; + $object->command = $data['command'] ?? null; + $object->description = $data['description'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/BotCommandScope.php b/src/TgBotLib/Objects/BotCommandScope.php index cdb751b..e28f91e 100644 --- a/src/TgBotLib/Objects/BotCommandScope.php +++ b/src/TgBotLib/Objects/BotCommandScope.php @@ -5,6 +5,9 @@ namespace TgBotLib\Objects; use TgBotLib\Interfaces\ObjectTypeInterface; + use TgBotLib\Objects\BotCommandScope\BotCommandScopeChat; + use TgBotLib\Objects\BotCommandScope\BotCommandScopeChatAdministrators; + use TgBotLib\Objects\BotCommandScope\BotCommandScopeChatMember; class BotCommandScope implements ObjectTypeInterface { @@ -76,9 +79,22 @@ */ public static function fromArray(array $data): ObjectTypeInterface { + if(isset($data['type'])) + { + switch($data['type']) + { + case 'chat': + return BotCommandScopeChat::fromArray($data); + case 'chat_administrators': + return BotCommandScopeChatAdministrators::fromArray($data); + case 'chat_member': + return BotCommandScopeChatMember::fromArray($data); + } + } + $object = new self(); - $object->type = $data['type']; + $object->type = $data['type'] ?? null; $object->chat_id = $data['chat_id'] ?? null; $object->user_id = $data['user_id'] ?? null; diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllChatAdministrators.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllChatAdministrators.php index 36e66f8..307448d 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllChatAdministrators.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllChatAdministrators.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\BotCommandScope; + use TgBotLib\Abstracts\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\BotCommandScope; @@ -20,7 +21,7 @@ private $chat_id; /** - * Scope type, must be chat_administrators + * Scope type, must be all_chat_administrators * * @return string */ @@ -61,8 +62,10 @@ public static function fromArray(array $data): ObjectTypeInterface { $object = new self(); - $object->type = $data['type']; - $object->chat_id = $data['chat_id']; + + $object->type = $data['type'] ?? BotCommandScopeType::AllChatAdministrators; + $object->chat_id = $data['chat_id'] ?? null; + return $object; } @@ -75,8 +78,10 @@ public static function fromBotCommandScope(BotCommandScope $botCommandScope): self { $object = new self(); + $object->type = $botCommandScope->getType(); $object->chat_id = $botCommandScope->getChatId(); + return $object; } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllGroupChats.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllGroupChats.php index 273c8a9..8e629e7 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllGroupChats.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllGroupChats.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\BotCommandScope; + use TgBotLib\Abstracts\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\BotCommandScope; @@ -46,7 +47,7 @@ { $object = new self(); - $object->type = $data['type']; + $object->type = $data['type'] ?? BotCommandScopeType::AllGroupChats; return $object; } diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllPrivateChats.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllPrivateChats.php index 9e1f882..b5e4e2c 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllPrivateChats.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeAllPrivateChats.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\BotCommandScope; + use TgBotLib\Abstracts\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\BotCommandScope; @@ -46,7 +47,7 @@ { $object = new self(); - $object->type = $data['type']; + $object->type = $data['type'] ?? BotCommandScopeType::AllPrivateChats; return $object; } diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChat.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChat.php index 8732974..f0f413e 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChat.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChat.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\BotCommandScope; + use TgBotLib\Abstracts\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\BotCommandScope; @@ -62,8 +63,8 @@ { $object = new self(); - $object->type = $data['type']; - $object->chat_id = $data['chat_id']; + $object->type = $data['type'] ?? BotCommandScopeType::Chat; + $object->chat_id = $data['chat_id'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatAdministrators.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatAdministrators.php index e214c27..12ce97a 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatAdministrators.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatAdministrators.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\BotCommandScope; + use TgBotLib\Abstracts\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\BotCommandScope; @@ -46,7 +47,7 @@ { $object = new self(); - $object->type = $data['type']; + $object->type = $data['type'] ?? BotCommandScopeType::ChatAdministrators; return $object; } diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatMember.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatMember.php index fb5f6d2..036a0cc 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatMember.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeChatMember.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\BotCommandScope; + use TgBotLib\Abstracts\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\BotCommandScope; @@ -77,9 +78,11 @@ public static function fromArray(array $data): ObjectTypeInterface { $object = new self(); - $object->type = $data['type']; - $object->chat_id = $data['chat_id']; - $object->user_id = $data['user_id']; + + $object->type = $data['type'] ?? BotCommandScopeType::ChatMember; + $object->chat_id = $data['chat_id'] ?? null; + $object->user_id = $data['user_id'] ?? null; + return $object; } diff --git a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeDefault.php b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeDefault.php index de30538..73467f3 100644 --- a/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeDefault.php +++ b/src/TgBotLib/Objects/BotCommandScope/BotCommandScopeDefault.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\BotCommandScope; + use TgBotLib\Abstracts\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\BotCommandScope; @@ -46,7 +47,7 @@ { $object = new self(); - $object->type = $data['type']; + $object->type = $data['type'] ?? BotCommandScopeType::Default; return $object; } diff --git a/src/TgBotLib/Objects/CallbackQuery.php b/src/TgBotLib/Objects/CallbackQuery.php index d3b9490..1f2b229 100644 --- a/src/TgBotLib/Objects/CallbackQuery.php +++ b/src/TgBotLib/Objects/CallbackQuery.php @@ -127,8 +127,8 @@ { return [ 'id' => $this->id, - 'from' => ($this->from instanceof User) ? $this->from->toArray() : null, - 'message' => ($this->message instanceof Message) ? $this->message->toArray() : null, + 'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : null, + 'message' => ($this->message instanceof ObjectTypeInterface) ? $this->message->toArray() : null, 'inline_message_id' => $this->inline_message_id, 'chat_instance' => $this->chat_instance, 'data' => $this->data, @@ -146,11 +146,11 @@ { $object = new self(); - $object->id = $data['id']; + $object->id = $data['id'] ?? null; $object->from = isset($data['from']) ? User::fromArray($data['from']) : null; $object->message = isset($data['message']) ? Message::fromArray($data['message']) : null; $object->inline_message_id = $data['inline_message_id'] ?? null; - $object->chat_instance = $data['chat_instance']; + $object->chat_instance = $data['chat_instance'] ?? null; $object->data = $data['data'] ?? null; $object->game_short_name = $data['game_short_name'] ?? null; diff --git a/src/TgBotLib/Objects/Chat.php b/src/TgBotLib/Objects/Chat.php index 7670b07..a04c926 100644 --- a/src/TgBotLib/Objects/Chat.php +++ b/src/TgBotLib/Objects/Chat.php @@ -218,7 +218,7 @@ * @see https://telegram.org/blog/topics-in-groups-collectible-usernames#topics-in-groups * @return bool */ - public function isIsForum(): bool + public function isForum(): bool { return $this->is_forum; } @@ -391,7 +391,7 @@ * @see https://core.telegram.org/bots/api#getchat * @return bool */ - public function isHasAggressiveAntiSpamEnabled(): bool + public function hasAggressiveAntiSpamEnabled(): bool { return $this->has_aggressive_anti_spam_enabled; } @@ -403,7 +403,7 @@ * @see https://core.telegram.org/bots/api#getchat * @return bool */ - public function isHasHiddenMembers(): bool + public function hasHiddenMembers(): bool { return $this->has_hidden_members; } @@ -414,7 +414,7 @@ * @see https://core.telegram.org/bots/api#getchat * @return bool */ - public function isHasProtectedContent(): bool + public function hasProtectedContent(): bool { return $this->has_protected_content; } @@ -479,7 +479,7 @@ 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'is_forum' => $this->is_forum, - 'photo' => ($this->photo instanceof ChatPhoto) ? $this->photo->toArray() : null, + 'photo' => ($this->photo instanceof ObjectTypeInterface) ? $this->photo->toArray() : null, 'active_usernames' => $this->active_usernames, 'emoji_status_custom_emoji_id' => $this->emoji_status_custom_emoji_id, 'bio' => $this->bio, @@ -489,8 +489,8 @@ 'join_by_request' => $this->join_by_request, 'description' => $this->description, 'invite_link' => $this->invite_link, - 'pinned_message' => ($this->pinned_message instanceof Message) ? $this->pinned_message->toArray() : null, - 'permissions' => ($this->permissions instanceof ChatPermissions) ? $this->permissions->toArray() : null, + 'pinned_message' => ($this->pinned_message instanceof ObjectTypeInterface) ? $this->pinned_message->toArray() : null, + 'permissions' => ($this->permissions instanceof ObjectTypeInterface) ? $this->permissions->toArray() : null, 'slow_mode_delay' => $this->slow_mode_delay, 'message_auto_delete_time' => $this->message_auto_delete_time, 'has_aggressive_anti_spam_enabled' => $this->has_aggressive_anti_spam_enabled, @@ -499,7 +499,7 @@ 'sticker_set_name' => $this->sticker_set_name, 'can_set_sticker_set' => $this->can_set_sticker_set, 'linked_chat_id' => $this->linked_chat_id, - 'location' => ($this->location instanceof ChatLocation) ? $this->location->toArray() : null, + 'location' => ($this->location instanceof ObjectTypeInterface) ? $this->location->toArray() : null, ]; } @@ -513,33 +513,33 @@ { $object = new self(); - $object->id = @$data['id']; - $object->type = @$data['type']; - $object->title = @$data['title'] ?? null; - $object->username = @$data['username'] ?? null; - $object->first_name = @$data['first_name'] ?? null; - $object->last_name = @$data['last_name'] ?? null; - $object->is_forum = @$data['is_forum'] ?? null; + $object->id = $data['id'] ?? null; + $object->type = $data['type'] ?? null; + $object->title = $data['title'] ?? null; + $object->username = $data['username'] ?? null; + $object->first_name = $data['first_name'] ?? null; + $object->last_name = $data['last_name'] ?? null; + $object->is_forum = $data['is_forum'] ?? null; $object->photo = isset($data['photo']) ? ChatPhoto::fromArray($data['photo']) : null; - $object->active_usernames = @$data['active_usernames'] ?? null; - $object->emoji_status_custom_emoji_id = @$data['emoji_status_custom_emoji_id'] ?? null; - $object->bio = @$data['bio'] ?? null; - $object->has_private_forwards = @$data['has_private_forwards'] ?? null; - $object->has_restricted_voice_and_video_messages = @$data['has_restricted_voice_and_video_messages'] ?? null; - $object->join_to_send_messages = @$data['join_to_send_messages'] ?? null; - $object->join_by_request = @$data['join_by_request'] ?? null; - $object->description = @$data['description'] ?? null; - $object->invite_link = @$data['invite_link'] ?? null; + $object->active_usernames = $data['active_usernames'] ?? null; + $object->emoji_status_custom_emoji_id = $data['emoji_status_custom_emoji_id'] ?? null; + $object->bio = $data['bio'] ?? null; + $object->has_private_forwards = $data['has_private_forwards'] ?? null; + $object->has_restricted_voice_and_video_messages = $data['has_restricted_voice_and_video_messages'] ?? null; + $object->join_to_send_messages = $data['join_to_send_messages'] ?? null; + $object->join_by_request = $data['join_by_request'] ?? null; + $object->description = $data['description'] ?? null; + $object->invite_link = $data['invite_link'] ?? null; $object->pinned_message = isset($data['pinned_message']) ? Message::fromArray($data['pinned_message']) : null; $object->permissions = isset($data['permissions']) ? ChatPermissions::fromArray($data['permissions']) : null; - $object->slow_mode_delay = @$data['slow_mode_delay'] ?? null; - $object->message_auto_delete_time = @$data['message_auto_delete_time'] ?? null; - $object->has_aggressive_anti_spam_enabled = @$data['has_aggressive_anti_spam_enabled'] ?? null; - $object->has_hidden_members = @$data['has_hidden_members'] ?? null; - $object->has_protected_content = @$data['has_protected_content'] ?? null; - $object->sticker_set_name = @$data['sticker_set_name'] ?? null; - $object->can_set_sticker_set = @$data['can_set_sticker_set'] ?? null; - $object->linked_chat_id = @$data['linked_chat_id'] ?? null; + $object->slow_mode_delay = $data['slow_mode_delay'] ?? null; + $object->message_auto_delete_time = $data['message_auto_delete_time'] ?? null; + $object->has_aggressive_anti_spam_enabled = $data['has_aggressive_anti_spam_enabled'] ?? null; + $object->has_hidden_members = $data['has_hidden_members'] ?? null; + $object->has_protected_content = $data['has_protected_content'] ?? null; + $object->sticker_set_name = $data['sticker_set_name'] ?? null; + $object->can_set_sticker_set = $data['can_set_sticker_set'] ?? null; + $object->linked_chat_id = $data['linked_chat_id'] ?? null; $object->location = isset($data['location']) ? ChatLocation::fromArray($data['location']) : null; return $object; diff --git a/src/TgBotLib/Objects/ChatAdministratorRights.php b/src/TgBotLib/Objects/ChatAdministratorRights.php index de2a167..d9fcfd6 100644 --- a/src/TgBotLib/Objects/ChatAdministratorRights.php +++ b/src/TgBotLib/Objects/ChatAdministratorRights.php @@ -73,7 +73,7 @@ * * @return bool */ - public function isIsAnonymous(): bool + public function isAnonymous(): bool { return $this->is_anonymous; } @@ -85,7 +85,7 @@ * * @return bool */ - public function isCanManageChat(): bool + public function canManageChat(): bool { return $this->can_manage_chat; } @@ -95,7 +95,7 @@ * * @return bool */ - public function isCanDeleteMessages(): bool + public function canDeleteMessages(): bool { return $this->can_delete_messages; } @@ -105,7 +105,7 @@ * * @return bool */ - public function isCanManageVideoChats(): bool + public function canManageVideoChats(): bool { return $this->can_manage_video_chats; } @@ -115,7 +115,7 @@ * * @return bool */ - public function isCanRestrictMembers(): bool + public function canRestrictMembers(): bool { return $this->can_restrict_members; } @@ -127,7 +127,7 @@ * * @return bool */ - public function isCanPromoteMembers(): bool + public function canPromoteMembers(): bool { return $this->can_promote_members; } @@ -137,7 +137,7 @@ * * @return bool */ - public function isCanChangeInfo(): bool + public function canChangeInfo(): bool { return $this->can_change_info; } @@ -147,7 +147,7 @@ * * @return bool */ - public function isCanInviteUsers(): bool + public function canInviteUsers(): bool { return $this->can_invite_users; } @@ -157,7 +157,7 @@ * * @return bool */ - public function isCanPostMessages(): bool + public function canPostMessages(): bool { return $this->can_post_messages; } @@ -167,7 +167,7 @@ * * @return bool */ - public function isCanEditMessages(): bool + public function canEditMessages(): bool { return $this->can_edit_messages; } @@ -177,7 +177,7 @@ * * @return bool */ - public function isCanPinMessages(): bool + public function canPinMessages(): bool { return $this->can_pin_messages; } @@ -187,7 +187,7 @@ * * @return bool */ - public function isCanManageTopics(): bool + public function canManageTopics(): bool { return $this->can_manage_topics; } @@ -220,6 +220,7 @@ * * @param array $data * @return ObjectTypeInterface + * @noinspection DuplicatedCode */ public static function fromArray(array $data): ObjectTypeInterface { diff --git a/src/TgBotLib/Objects/ChatInviteLink.php b/src/TgBotLib/Objects/ChatInviteLink.php index dbfa345..f864c39 100644 --- a/src/TgBotLib/Objects/ChatInviteLink.php +++ b/src/TgBotLib/Objects/ChatInviteLink.php @@ -79,7 +79,7 @@ * * @return bool */ - public function isCreatesJoinRequest(): bool + public function createsJoinRequest(): bool { return $this->creates_join_request; } @@ -89,7 +89,7 @@ * * @return bool */ - public function isIsPrimary(): bool + public function isPrimary(): bool { return $this->is_primary; } @@ -99,7 +99,7 @@ * * @return bool */ - public function isIsRevoked(): bool + public function isRevoked(): bool { return $this->is_revoked; } @@ -174,15 +174,15 @@ { $object = new self(); - $object->invite_link = $data['invite_link']; + $object->invite_link = $data['invite_link'] ?? null; $object->creator = isset($data['creator']) ? User::fromArray($data['creator']) : null; - $object->creates_join_request = $data['creates_join_request']; - $object->is_primary = $data['is_primary']; - $object->is_revoked = $data['is_revoked']; - $object->name = $data['name']; - $object->expire_date = $data['expire_date']; - $object->member_limit = $data['member_limit']; - $object->pending_join_request_count = $data['pending_join_request_count']; + $object->creates_join_request = $data['creates_join_request'] ?? null; + $object->is_primary = $data['is_primary'] ?? null; + $object->is_revoked = $data['is_revoked'] ?? null; + $object->name = $data['name'] ?? null; + $object->expire_date = $data['expire_date'] ?? null; + $object->member_limit = $data['member_limit'] ?? null; + $object->pending_join_request_count = $data['pending_join_request_count'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/ChatJoinRequest.php b/src/TgBotLib/Objects/ChatJoinRequest.php index 04c4352..5362bdf 100644 --- a/src/TgBotLib/Objects/ChatJoinRequest.php +++ b/src/TgBotLib/Objects/ChatJoinRequest.php @@ -110,12 +110,12 @@ public function toArray(): array { return [ - 'chat' => ($this->chat instanceof Chat) ? $this->chat->toArray() : $this->chat, - 'from' => ($this->from instanceof User) ? $this->from->toArray() : $this->from, + 'chat' => ($this->chat instanceof ObjectTypeInterface) ? $this->chat->toArray() : $this->chat, + 'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : $this->from, 'user_chat_id' => $this->user_chat_id, 'date' => $this->date, 'bio' => $this->bio, - 'invite_link' => ($this->invite_link instanceof ChatInviteLink) ? $this->invite_link->toArray() : $this->invite_link, + 'invite_link' => ($this->invite_link instanceof ObjectTypeInterface) ? $this->invite_link->toArray() : $this->invite_link, ]; } diff --git a/src/TgBotLib/Objects/ChatLocation.php b/src/TgBotLib/Objects/ChatLocation.php index 3309586..2dc550c 100644 --- a/src/TgBotLib/Objects/ChatLocation.php +++ b/src/TgBotLib/Objects/ChatLocation.php @@ -46,7 +46,7 @@ public function toArray(): array { return [ - 'location' => ($this->location instanceof Location) ? $this->location->toArray() : $this->location, + 'location' => ($this->location instanceof ObjectTypeInterface) ? $this->location->toArray() : $this->location, 'address' => $this->address, ]; } @@ -62,7 +62,7 @@ $object = new self(); $object->location = isset($data['location']) ? Location::fromArray($data['location']) : null; - $object->address = isset($data['address']) ? $data['address'] : null; + $object->address = $data['address'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/ChatMember.php b/src/TgBotLib/Objects/ChatMember.php index 5e2e5a7..887faa4 100644 --- a/src/TgBotLib/Objects/ChatMember.php +++ b/src/TgBotLib/Objects/ChatMember.php @@ -183,7 +183,7 @@ * * @return bool */ - public function isIsMember(): bool + public function isMember(): bool { return $this->is_member; } @@ -193,7 +193,7 @@ * * @return bool */ - public function isIsAnonymous(): bool + public function isAnonymous(): bool { return $this->is_anonymous; } @@ -203,7 +203,7 @@ * * @return bool */ - public function isCanSendMessages(): bool + public function canSendMessages(): bool { return $this->can_send_messages; } @@ -213,7 +213,7 @@ * * @return bool */ - public function isCanSendAudios(): bool + public function canSendAudios(): bool { return $this->can_send_audios; } @@ -223,7 +223,7 @@ * * @return bool */ - public function isCanSendDocuments(): bool + public function canSendDocuments(): bool { return $this->can_send_documents; } @@ -233,7 +233,7 @@ * * @return bool */ - public function isCanSendPhotos(): bool + public function canSendPhotos(): bool { return $this->can_send_photos; } @@ -243,7 +243,7 @@ * * @return bool */ - public function isCanSendVideos(): bool + public function canSendVideos(): bool { return $this->can_send_videos; } @@ -253,7 +253,7 @@ * * @return bool */ - public function isCanSendVideoNotes(): bool + public function canSendVideoNotes(): bool { return $this->can_send_video_notes; } @@ -263,7 +263,7 @@ * * @return bool */ - public function isCanSendVoiceNotes(): bool + public function canSendVoiceNotes(): bool { return $this->can_send_voice_notes; } @@ -273,7 +273,7 @@ * * @return bool */ - public function isCanSendPolls(): bool + public function canSendPolls(): bool { return $this->can_send_polls; } @@ -283,7 +283,7 @@ * * @return bool */ - public function isCanSendOtherMessages(): bool + public function canSendOtherMessages(): bool { return $this->can_send_other_messages; } @@ -293,7 +293,7 @@ * * @return bool */ - public function isCanAddWebPagePreviews(): bool + public function canAddWebPagePreviews(): bool { return $this->can_add_web_page_previews; } @@ -303,7 +303,7 @@ * * @return bool */ - public function isCanChangeInfo(): bool + public function canChangeInfo(): bool { return $this->can_change_info; } @@ -315,7 +315,7 @@ * * @return bool */ - public function isCanManageChat(): bool + public function canManageChat(): bool { return $this->can_manage_chat; } @@ -325,7 +325,7 @@ * * @return bool */ - public function isCanDeleteMessages(): bool + public function canDeleteMessages(): bool { return $this->can_delete_messages; } @@ -335,7 +335,7 @@ * * @return bool */ - public function isCanManageVideoChats(): bool + public function canManageVideoChats(): bool { return $this->can_manage_video_chats; } @@ -345,7 +345,7 @@ * * @return bool */ - public function isCanRestrictMembers(): bool + public function canRestrictMembers(): bool { return $this->can_restrict_members; } @@ -357,7 +357,7 @@ * * @return bool */ - public function isCanPromoteMembers(): bool + public function canPromoteMembers(): bool { return $this->can_promote_members; } @@ -367,7 +367,7 @@ * * @return bool */ - public function isCanInviteUsers(): bool + public function canInviteUsers(): bool { return $this->can_invite_users; } @@ -377,7 +377,7 @@ * * @return bool */ - public function isCanPostMessages(): bool + public function canPostMessages(): bool { return $this->can_post_messages; } @@ -387,7 +387,7 @@ * * @return bool */ - public function isCanEditMessages(): bool + public function canEditMessages(): bool { return $this->can_edit_messages; } @@ -397,7 +397,7 @@ * * @return bool */ - public function isCanPinMessages(): bool + public function canPinMessages(): bool { return $this->can_pin_messages; } @@ -407,7 +407,7 @@ * * @return bool */ - public function isCanManageTopics(): bool + public function canManageTopics(): bool { return $this->can_manage_topics; } @@ -417,7 +417,7 @@ * * @return bool */ - public function isCanBeEdited(): bool + public function canBeEdited(): bool { return $this->can_be_edited; } @@ -441,7 +441,7 @@ { return [ 'status' => $this->status, - 'user' => ($this->user instanceof User) ? $this->user->toArray() : $this->user, + 'user' => ($this->user instanceof ObjectTypeInterface) ? $this->user->toArray() : $this->user, 'custom_title' => $this->custom_title, 'is_member' => $this->is_member, 'is_anonymous' => $this->is_anonymous, @@ -476,39 +476,40 @@ * * @param array $data * @return ObjectTypeInterface + * @noinspection DuplicatedCode */ public static function fromArray(array $data): ObjectTypeInterface { $object = new static(); - $object->status = @$data['status']; + $object->status = $data['status'] ?? null; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; - $object->custom_title = @$data['custom_title'] ?? null; - $object->is_member = @$data['is_member'] ?? false; - $object->is_anonymous = @$data['is_anonymous'] ?? false; - $object->can_send_messages = @$data['can_send_messages'] ?? false; - $object->can_send_audios = @$data['can_send_audios'] ?? false; - $object->can_send_documents = @$data['can_send_documents'] ?? false; - $object->can_send_photos = @$data['can_send_photos'] ?? false; - $object->can_send_videos = @$data['can_send_videos'] ?? false; - $object->can_send_video_notes = @$data['can_send_video_notes'] ?? false; - $object->can_send_voice_notes = @$data['can_send_voice_notes'] ?? false; - $object->can_send_polls = @$data['can_send_polls'] ?? false; - $object->can_send_other_messages = @$data['can_send_other_messages'] ?? false; - $object->can_add_web_page_previews = @$data['can_add_web_page_previews'] ?? false; - $object->can_change_info = @$data['can_change_info'] ?? false; - $object->can_manage_chat = @$data['can_manage_chat'] ?? false; - $object->can_delete_messages = @$data['can_delete_messages'] ?? false; - $object->can_manage_video_chats = @$data['can_manage_video_chats'] ?? false; - $object->can_restrict_members = @$data['can_restrict_members'] ?? false; - $object->can_promote_members = @$data['can_promote_members'] ?? false; - $object->can_invite_users = @$data['can_invite_users'] ?? false; - $object->can_post_messages = @$data['can_post_messages'] ?? false; - $object->can_edit_messages = @$data['can_edit_messages'] ?? false; - $object->can_pin_messages = @$data['can_pin_messages'] ?? false; - $object->can_manage_topics = @$data['can_manage_topics'] ?? false; - $object->can_be_edited = @$data['can_be_edited'] ?? false; - $object->until_date = @$data['until_date'] ?? null; + $object->custom_title = $data['custom_title'] ?? null; + $object->is_member = $data['is_member'] ?? false; + $object->is_anonymous = $data['is_anonymous'] ?? false; + $object->can_send_messages = $data['can_send_messages'] ?? false; + $object->can_send_audios = $data['can_send_audios'] ?? false; + $object->can_send_documents = $data['can_send_documents'] ?? false; + $object->can_send_photos = $data['can_send_photos'] ?? false; + $object->can_send_videos = $data['can_send_videos'] ?? false; + $object->can_send_video_notes = $data['can_send_video_notes'] ?? false; + $object->can_send_voice_notes = $data['can_send_voice_notes'] ?? false; + $object->can_send_polls = $data['can_send_polls'] ?? false; + $object->can_send_other_messages = $data['can_send_other_messages'] ?? false; + $object->can_add_web_page_previews = $data['can_add_web_page_previews'] ?? false; + $object->can_change_info = $data['can_change_info'] ?? false; + $object->can_manage_chat = $data['can_manage_chat'] ?? false; + $object->can_delete_messages = $data['can_delete_messages'] ?? false; + $object->can_manage_video_chats = $data['can_manage_video_chats'] ?? false; + $object->can_restrict_members = $data['can_restrict_members'] ?? false; + $object->can_promote_members = $data['can_promote_members'] ?? false; + $object->can_invite_users = $data['can_invite_users'] ?? false; + $object->can_post_messages = $data['can_post_messages'] ?? false; + $object->can_edit_messages = $data['can_edit_messages'] ?? false; + $object->can_pin_messages = $data['can_pin_messages'] ?? false; + $object->can_manage_topics = $data['can_manage_topics'] ?? false; + $object->can_be_edited = $data['can_be_edited'] ?? false; + $object->until_date = $data['until_date'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberAdministrator.php b/src/TgBotLib/Objects/ChatMember/ChatMemberAdministrator.php index 029df69..7913b83 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberAdministrator.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberAdministrator.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\ChatMember; + use TgBotLib\Abstracts\ChatMemberStatus; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\ChatMember; use TgBotLib\Objects\User; @@ -115,7 +116,7 @@ * * @return bool */ - public function isCanBeEdited(): bool + public function canBeEdited(): bool { return $this->can_be_edited; } @@ -125,7 +126,7 @@ * * @return bool */ - public function isIsAnonymous(): bool + public function isAnonymous(): bool { return $this->is_anonymous; } @@ -137,7 +138,7 @@ * * @return bool */ - public function isCanManageChat(): bool + public function canManageChat(): bool { return $this->can_manage_chat; } @@ -147,7 +148,7 @@ * * @return bool */ - public function isCanDeleteMessages(): bool + public function canDeleteMessages(): bool { return $this->can_delete_messages; } @@ -157,7 +158,7 @@ * * @return bool */ - public function isCanManageVideoChats(): bool + public function canManageVideoChats(): bool { return $this->can_manage_video_chats; } @@ -167,7 +168,7 @@ * * @return bool */ - public function isCanRestrictMembers(): bool + public function canRestrictMembers(): bool { return $this->can_restrict_members; } @@ -179,7 +180,7 @@ * * @return bool */ - public function isCanPromoteMembers(): bool + public function canPromoteMembers(): bool { return $this->can_promote_members; } @@ -189,7 +190,7 @@ * * @return bool */ - public function isCanChangeInfo(): bool + public function canChangeInfo(): bool { return $this->can_change_info; } @@ -199,7 +200,7 @@ * * @return bool */ - public function isCanInviteUsers(): bool + public function canInviteUsers(): bool { return $this->can_invite_users; } @@ -209,7 +210,7 @@ * * @return bool */ - public function isCanPostMessages(): bool + public function canPostMessages(): bool { return $this->can_post_messages; } @@ -219,7 +220,7 @@ * * @return bool */ - public function isCanEditMessages(): bool + public function canEditMessages(): bool { return $this->can_edit_messages; } @@ -229,7 +230,7 @@ * * @return bool */ - public function isCanPinMessages(): bool + public function canPinMessages(): bool { return $this->can_pin_messages; } @@ -239,7 +240,7 @@ * * @return bool */ - public function isCanManageTopics(): bool + public function canManageTopics(): bool { return $this->can_manage_topics; } @@ -291,22 +292,22 @@ { $object = new self(); - $object->status = $data['status']; + $object->status = $data['status'] ?? ChatMemberStatus::Administrator; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; - $object->can_be_edited = @$data['can_be_edited'] ?? false; - $object->is_anonymous = @$data['is_anonymous'] ?? false; - $object->can_manage_chat = @$data['can_manage_chat'] ?? false; - $object->can_delete_messages = @$data['can_delete_messages'] ?? false; - $object->can_manage_video_chats = @$data['can_manage_video_chats'] ?? false; - $object->can_restrict_members = @$data['can_restrict_members'] ?? false; - $object->can_promote_members = @$data['can_promote_members'] ?? false; - $object->can_change_info = @$data['can_change_info'] ?? false; - $object->can_invite_users = @$data['can_invite_users'] ?? false; - $object->can_post_messages = @$data['can_post_messages'] ?? false; - $object->can_edit_messages = @$data['can_edit_messages'] ?? false; - $object->can_pin_messages = @$data['can_pin_messages'] ?? false; - $object->can_manage_topics = @$data['can_manage_topics'] ?? false; - $object->custom_title = @$data['custom_title'] ?? null; + $object->can_be_edited = $data['can_be_edited'] ?? false; + $object->is_anonymous = $data['is_anonymous'] ?? false; + $object->can_manage_chat = $data['can_manage_chat'] ?? false; + $object->can_delete_messages = $data['can_delete_messages'] ?? false; + $object->can_manage_video_chats = $data['can_manage_video_chats'] ?? false; + $object->can_restrict_members = $data['can_restrict_members'] ?? false; + $object->can_promote_members = $data['can_promote_members'] ?? false; + $object->can_change_info = $data['can_change_info'] ?? false; + $object->can_invite_users = $data['can_invite_users'] ?? false; + $object->can_post_messages = $data['can_post_messages'] ?? false; + $object->can_edit_messages = $data['can_edit_messages'] ?? false; + $object->can_pin_messages = $data['can_pin_messages'] ?? false; + $object->can_manage_topics = $data['can_manage_topics'] ?? false; + $object->custom_title = $data['custom_title'] ?? null; return $object; } @@ -323,19 +324,19 @@ $object->status = $chatMember->getStatus(); $object->user = $chatMember->getUser(); - $object->can_be_edited = $chatMember->isCanBeEdited(); - $object->is_anonymous = $chatMember->isIsAnonymous(); - $object->can_manage_chat = $chatMember->isCanManageChat(); - $object->can_delete_messages = $chatMember->isCanDeleteMessages(); - $object->can_manage_video_chats = $chatMember->isCanManageVideoChats(); - $object->can_restrict_members = $chatMember->isCanRestrictMembers(); - $object->can_promote_members = $chatMember->isCanPromoteMembers(); - $object->can_change_info = $chatMember->isCanChangeInfo(); - $object->can_invite_users = $chatMember->isCanInviteUsers(); - $object->can_post_messages = $chatMember->isCanPostMessages(); - $object->can_edit_messages = $chatMember->isCanEditMessages(); - $object->can_pin_messages = $chatMember->isCanPinMessages(); - $object->can_manage_topics = $chatMember->isCanManageTopics(); + $object->can_be_edited = $chatMember->canBeEdited(); + $object->is_anonymous = $chatMember->isAnonymous(); + $object->can_manage_chat = $chatMember->canManageChat(); + $object->can_delete_messages = $chatMember->canDeleteMessages(); + $object->can_manage_video_chats = $chatMember->canManageVideoChats(); + $object->can_restrict_members = $chatMember->canRestrictMembers(); + $object->can_promote_members = $chatMember->canPromoteMembers(); + $object->can_change_info = $chatMember->canChangeInfo(); + $object->can_invite_users = $chatMember->canInviteUsers(); + $object->can_post_messages = $chatMember->canPostMessages(); + $object->can_edit_messages = $chatMember->canEditMessages(); + $object->can_pin_messages = $chatMember->canPinMessages(); + $object->can_manage_topics = $chatMember->canManageTopics(); $object->custom_title = $chatMember->getCustomTitle(); return $object; diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberBanned.php b/src/TgBotLib/Objects/ChatMember/ChatMemberBanned.php index 163845c..e5a8121 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberBanned.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberBanned.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\ChatMember; + use TgBotLib\Abstracts\ChatMemberStatus; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\ChatMember; use TgBotLib\Objects\User; @@ -78,9 +79,10 @@ public static function fromArray(array $data): ObjectTypeInterface { $object = new self(); - $object->status = $data['status']; + + $object->status = $data['status'] ?? ChatMemberStatus::Kicked; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; - $object->until_date = $data['until_date']; + $object->until_date = $data['until_date'] ?? null; return $object; } @@ -94,6 +96,7 @@ public static function fromChatMember(ChatMember $chatMember): ChatMemberBanned { $object = new self(); + $object->status = $chatMember->getStatus(); $object->user = $chatMember->getUser(); $object->until_date = $chatMember->getUntilDate(); diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberLeft.php b/src/TgBotLib/Objects/ChatMember/ChatMemberLeft.php index 4231ae8..742c3da 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberLeft.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberLeft.php @@ -1,7 +1,10 @@ status = $data['status']; - $object->user = User::fromArray($data['user']); + + $object->status = $data['status'] ?? ChatMemberStatus::Left; + $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; + return $object; } @@ -74,8 +79,10 @@ public static function fromChatMember(ChatMember $chatMember): self { $object = new self(); + $object->status = $chatMember->getStatus(); $object->user = $chatMember->getUser(); + return $object; } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberMember.php b/src/TgBotLib/Objects/ChatMember/ChatMemberMember.php index d561f49..d674d9b 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberMember.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberMember.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\ChatMember; + use TgBotLib\Abstracts\ChatMemberStatus; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\ChatMember; use TgBotLib\Objects\User; @@ -63,7 +64,7 @@ { $object = new self(); - $object->status = $data['status']; + $object->status = $data['status'] ?? ChatMemberStatus::Member; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; return $object; diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberOwner.php b/src/TgBotLib/Objects/ChatMember/ChatMemberOwner.php index 0ebcb72..6de0f66 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberOwner.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberOwner.php @@ -56,7 +56,7 @@ * * @return bool */ - public function isIsAnonymous(): bool + public function isAnonymous(): bool { return $this->is_anonymous; } @@ -95,10 +95,12 @@ public static function fromArray(array $data): ObjectTypeInterface { $object = new ChatMemberOwner(); + $object->status = $data['status'] ?? ChatMemberStatus::Creator; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->is_anonymous = $data['is_anonymous'] ?? false; $object->custom_title = $data['custom_title'] ?? null; + return $object; } @@ -111,10 +113,12 @@ public static function fromChatMember(ChatMember $chatMember): ChatMemberOwner { $object = new ChatMemberOwner(); + $object->status = $chatMember->getStatus(); $object->user = $chatMember->getUser(); - $object->is_anonymous = $chatMember->isIsAnonymous(); + $object->is_anonymous = $chatMember->isAnonymous(); $object->custom_title = $chatMember->getCustomTitle(); + return $object; } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/ChatMember/ChatMemberRestricted.php b/src/TgBotLib/Objects/ChatMember/ChatMemberRestricted.php index c505abe..172f867 100644 --- a/src/TgBotLib/Objects/ChatMember/ChatMemberRestricted.php +++ b/src/TgBotLib/Objects/ChatMember/ChatMemberRestricted.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\ChatMember; + use TgBotLib\Abstracts\ChatMemberStatus; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\ChatMember; use TgBotLib\Objects\User; @@ -125,7 +126,7 @@ * * @return bool */ - public function isIsMember(): bool + public function isMember(): bool { return $this->is_member; } @@ -135,7 +136,7 @@ * * @return bool */ - public function isCanSendMessages(): bool + public function canSendMessages(): bool { return $this->can_send_messages; } @@ -145,7 +146,7 @@ * * @return bool */ - public function isCanSendAudios(): bool + public function canSendAudios(): bool { return $this->can_send_audios; } @@ -155,7 +156,7 @@ * * @return bool */ - public function isCanSendDocuments(): bool + public function canSendDocuments(): bool { return $this->can_send_documents; } @@ -165,7 +166,7 @@ * * @return bool */ - public function isCanSendPhotos(): bool + public function canSendPhotos(): bool { return $this->can_send_photos; } @@ -175,7 +176,7 @@ * * @return bool */ - public function isCanSendVideos(): bool + public function canSendVideos(): bool { return $this->can_send_videos; } @@ -185,7 +186,7 @@ * * @return bool */ - public function isCanSendVideoNotes(): bool + public function canSendVideoNotes(): bool { return $this->can_send_video_notes; } @@ -195,7 +196,7 @@ * * @return bool */ - public function isCanSendVoiceNotes(): bool + public function canSendVoiceNotes(): bool { return $this->can_send_voice_notes; } @@ -205,7 +206,7 @@ * * @return bool */ - public function isCanSendPolls(): bool + public function canSendPolls(): bool { return $this->can_send_polls; } @@ -215,7 +216,7 @@ * * @return bool */ - public function isCanSendOtherMessages(): bool + public function canSendOtherMessages(): bool { return $this->can_send_other_messages; } @@ -225,7 +226,7 @@ * * @return bool */ - public function isCanAddWebPagePreviews(): bool + public function canAddWebPagePreviews(): bool { return $this->can_add_web_page_previews; } @@ -235,7 +236,7 @@ * * @return bool */ - public function isCanChangeInfo(): bool + public function canChangeInfo(): bool { return $this->can_change_info; } @@ -245,7 +246,7 @@ * * @return bool */ - public function isCanInviteUsers(): bool + public function canInviteUsers(): bool { return $this->can_invite_users; } @@ -255,7 +256,7 @@ * * @return bool */ - public function isCanPinMessages(): bool + public function canPinMessages(): bool { return $this->can_pin_messages; } @@ -265,7 +266,7 @@ * * @return bool */ - public function isCanManageTopics(): bool + public function canManageTopics(): bool { return $this->can_manage_topics; } @@ -314,29 +315,30 @@ * * @param array $data * @return ObjectTypeInterface + * @noinspection DuplicatedCode */ public static function fromArray(array $data): ObjectTypeInterface { $object = new static(); - $object->status = $data['status']; + $object->status = $data['status'] ?? ChatMemberStatus::Restricted; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; - $object->is_member = @$data['is_member'] ?? false; - $object->can_send_messages = @$data['can_send_messages'] ?? false; - $object->can_send_audios = @$data['can_send_audios'] ?? false; - $object->can_send_documents = @$data['can_send_documents'] ?? false; - $object->can_send_photos = @$data['can_send_photos'] ?? false; - $object->can_send_videos = @$data['can_send_videos'] ?? false; - $object->can_send_video_notes = @$data['can_send_video_notes'] ?? false; - $object->can_send_voice_notes = @$data['can_send_voice_notes'] ?? false; - $object->can_send_polls = @$data['can_send_polls'] ?? false; - $object->can_send_other_messages = @$data['can_send_other_messages'] ?? false; - $object->can_add_web_page_previews = @$data['can_add_web_page_previews'] ?? false; - $object->can_change_info = @$data['can_change_info'] ?? false; - $object->can_invite_users = @$data['can_invite_users'] ?? false; - $object->can_pin_messages = @$data['can_pin_messages'] ?? false; - $object->can_manage_topics = @$data['can_manage_topics'] ?? false; - $object->until_date = @$data['until_date'] ?? 0; + $object->is_member = $data['is_member'] ?? false; + $object->can_send_messages = $data['can_send_messages'] ?? false; + $object->can_send_audios = $data['can_send_audios'] ?? false; + $object->can_send_documents = $data['can_send_documents'] ?? false; + $object->can_send_photos = $data['can_send_photos'] ?? false; + $object->can_send_videos = $data['can_send_videos'] ?? false; + $object->can_send_video_notes = $data['can_send_video_notes'] ?? false; + $object->can_send_voice_notes = $data['can_send_voice_notes'] ?? false; + $object->can_send_polls = $data['can_send_polls'] ?? false; + $object->can_send_other_messages = $data['can_send_other_messages'] ?? false; + $object->can_add_web_page_previews = $data['can_add_web_page_previews'] ?? false; + $object->can_change_info = $data['can_change_info'] ?? false; + $object->can_invite_users = $data['can_invite_users'] ?? false; + $object->can_pin_messages = $data['can_pin_messages'] ?? false; + $object->can_manage_topics = $data['can_manage_topics'] ?? false; + $object->until_date = $data['until_date'] ?? 0; return $object; } @@ -353,21 +355,21 @@ $object->status = $chatMember->getStatus(); $object->user = $chatMember->getUser(); - $object->is_member = $chatMember->isIsMember(); - $object->can_send_messages = $chatMember->isCanSendMessages(); - $object->can_send_audios = $chatMember->isCanSendAudios(); - $object->can_send_documents = $chatMember->isCanSendDocuments(); - $object->can_send_photos = $chatMember->isCanSendPhotos(); - $object->can_send_videos = $chatMember->isCanSendVideos(); - $object->can_send_video_notes = $chatMember->isCanSendVideoNotes(); - $object->can_send_voice_notes = $chatMember->isCanSendVoiceNotes(); - $object->can_send_polls = $chatMember->isCanSendPolls(); - $object->can_send_other_messages = $chatMember->isCanSendOtherMessages(); - $object->can_add_web_page_previews = $chatMember->isCanAddWebPagePreviews(); - $object->can_change_info = $chatMember->isCanChangeInfo(); - $object->can_invite_users = $chatMember->isCanInviteUsers(); - $object->can_pin_messages = $chatMember->isCanPinMessages(); - $object->can_manage_topics = $chatMember->isCanManageTopics(); + $object->is_member = $chatMember->isMember(); + $object->can_send_messages = $chatMember->canSendMessages(); + $object->can_send_audios = $chatMember->canSendAudios(); + $object->can_send_documents = $chatMember->canSendDocuments(); + $object->can_send_photos = $chatMember->canSendPhotos(); + $object->can_send_videos = $chatMember->canSendVideos(); + $object->can_send_video_notes = $chatMember->canSendVideoNotes(); + $object->can_send_voice_notes = $chatMember->canSendVoiceNotes(); + $object->can_send_polls = $chatMember->canSendPolls(); + $object->can_send_other_messages = $chatMember->canSendOtherMessages(); + $object->can_add_web_page_previews = $chatMember->canAddWebPagePreviews(); + $object->can_change_info = $chatMember->canChangeInfo(); + $object->can_invite_users = $chatMember->canInviteUsers(); + $object->can_pin_messages = $chatMember->canPinMessages(); + $object->can_manage_topics = $chatMember->canManageTopics(); $object->until_date = $chatMember->getUntilDate(); return $object; diff --git a/src/TgBotLib/Objects/ChatMemberUpdated.php b/src/TgBotLib/Objects/ChatMemberUpdated.php index fbeb5a7..eb26761 100644 --- a/src/TgBotLib/Objects/ChatMemberUpdated.php +++ b/src/TgBotLib/Objects/ChatMemberUpdated.php @@ -128,7 +128,7 @@ $object->chat = isset($data['chat']) ? Chat::fromArray($data['chat']) : new Chat(); $object->from = isset($data['from']) ? User::fromArray($data['from']) : new User(); - $object->date = $data['date']; + $object->date = $data['date'] ?? 0; $object->old_chat_member = isset($data['old_chat_member']) ? ChatMember::fromArray($data['old_chat_member']) : new ChatMember(); $object->new_chat_member = isset($data['new_chat_member']) ? ChatMember::fromArray($data['new_chat_member']) : new ChatMember(); $object->invite_link = isset($data['invite_link']) ? ChatInviteLink::fromArray($data['invite_link']) : null; diff --git a/src/TgBotLib/Objects/ChatPermissions.php b/src/TgBotLib/Objects/ChatPermissions.php index f963272..c685ea6 100644 --- a/src/TgBotLib/Objects/ChatPermissions.php +++ b/src/TgBotLib/Objects/ChatPermissions.php @@ -83,7 +83,7 @@ * * @return bool */ - public function isCanSendMessages(): bool + public function canSendMessages(): bool { return $this->can_send_messages; } @@ -93,7 +93,7 @@ * * @return bool */ - public function isCanSendAudios(): bool + public function canSendAudios(): bool { return $this->can_send_audios; } @@ -103,7 +103,7 @@ * * @return bool */ - public function isCanSendDocuments(): bool + public function canSendDocuments(): bool { return $this->can_send_documents; } @@ -113,7 +113,7 @@ * * @return bool */ - public function isCanSendPhotos(): bool + public function canSendPhotos(): bool { return $this->can_send_photos; } @@ -123,7 +123,7 @@ * * @return bool */ - public function isCanSendVideos(): bool + public function canSendVideos(): bool { return $this->can_send_videos; } @@ -133,7 +133,7 @@ * * @return bool */ - public function isCanSendVideosNotes(): bool + public function canSendVideosNotes(): bool { return $this->can_send_videos_notes; } @@ -143,7 +143,7 @@ * * @return bool */ - public function isCanSendVoiceNotes(): bool + public function canSendVoiceNotes(): bool { return $this->can_send_voice_notes; } @@ -153,7 +153,7 @@ * * @return bool */ - public function isCanSendPolls(): bool + public function canSendPolls(): bool { return $this->can_send_polls; } @@ -163,7 +163,7 @@ * * @return bool */ - public function isCanSendOtherMessages(): bool + public function canSendOtherMessages(): bool { return $this->can_send_other_messages; } @@ -173,7 +173,7 @@ * * @return bool */ - public function isCanAddWebPagePreviews(): bool + public function canAddWebPagePreviews(): bool { return $this->can_add_web_page_previews; } @@ -184,7 +184,7 @@ * * @return bool */ - public function isCanChangeInfo(): bool + public function canChangeInfo(): bool { return $this->can_change_info; } @@ -194,7 +194,7 @@ * * @return bool */ - public function isCanInviteUsers(): bool + public function canInviteUsers(): bool { return $this->can_invite_users; } @@ -204,7 +204,7 @@ * * @return bool */ - public function isCanPinMessages(): bool + public function canPinMessages(): bool { return $this->can_pin_messages; } @@ -215,7 +215,7 @@ * * @return bool */ - public function isCanManageTopics(): bool + public function canManageTopics(): bool { return $this->can_manage_topics; } @@ -250,25 +250,26 @@ * * @param array $data * @return ObjectTypeInterface + * @noinspection DuplicatedCode */ public static function fromArray(array $data): ObjectTypeInterface { $object = new self(); - $object->can_send_messages = @$data['can_send_messages'] ?? false; - $object->can_send_audios = @$data['can_send_audios'] ?? false; - $object->can_send_documents = @$data['can_send_documents'] ?? false; - $object->can_send_photos = @$data['can_send_photos'] ?? false; - $object->can_send_videos = @$data['can_send_videos'] ?? false; - $object->can_send_videos_notes = @$data['can_send_videos_notes'] ?? false; - $object->can_send_voice_notes = @$data['can_send_voice_notes'] ?? false; - $object->can_send_polls = @$data['can_send_polls'] ?? false; - $object->can_send_other_messages = @$data['can_send_other_messages'] ?? false; - $object->can_add_web_page_previews = @$data['can_add_web_page_previews'] ?? false; - $object->can_change_info = @$data['can_change_info'] ?? false; - $object->can_invite_users = @$data['can_invite_users'] ?? false; - $object->can_pin_messages = @$data['can_pin_messages'] ?? false; - $object->can_manage_topics = @$data['can_manage_topics'] ?? false; + $object->can_send_messages = $data['can_send_messages'] ?? false; + $object->can_send_audios = $data['can_send_audios'] ?? false; + $object->can_send_documents = $data['can_send_documents'] ?? false; + $object->can_send_photos = $data['can_send_photos'] ?? false; + $object->can_send_videos = $data['can_send_videos'] ?? false; + $object->can_send_videos_notes = $data['can_send_videos_notes'] ?? false; + $object->can_send_voice_notes = $data['can_send_voice_notes'] ?? false; + $object->can_send_polls = $data['can_send_polls'] ?? false; + $object->can_send_other_messages = $data['can_send_other_messages'] ?? false; + $object->can_add_web_page_previews = $data['can_add_web_page_previews'] ?? false; + $object->can_change_info = $data['can_change_info'] ?? false; + $object->can_invite_users = $data['can_invite_users'] ?? false; + $object->can_pin_messages = $data['can_pin_messages'] ?? false; + $object->can_manage_topics = $data['can_manage_topics'] ?? false; return $object; } diff --git a/src/TgBotLib/Objects/ChatPhoto.php b/src/TgBotLib/Objects/ChatPhoto.php index fdc98cf..fc6a8c9 100644 --- a/src/TgBotLib/Objects/ChatPhoto.php +++ b/src/TgBotLib/Objects/ChatPhoto.php @@ -1,5 +1,7 @@ small_file_id = $data['small_file_id']; - $object->small_file_unique_id = $data['small_file_unique_id']; - $object->big_file_id = $data['big_file_id']; - $object->big_file_unique_id = $data['big_file_unique_id']; + $object->small_file_id = $data['small_file_id'] ?? null; + $object->small_file_unique_id = $data['small_file_unique_id'] ?? null; + $object->big_file_id = $data['big_file_id'] ?? null; + $object->big_file_unique_id = $data['big_file_unique_id'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/ChatShared.php b/src/TgBotLib/Objects/ChatShared.php index 290dfef..495e874 100644 --- a/src/TgBotLib/Objects/ChatShared.php +++ b/src/TgBotLib/Objects/ChatShared.php @@ -65,8 +65,8 @@ { $object = new self(); - $object->request_id = @$data['request_id']; - $object->chat_id = @$data['chat_id']; + $object->request_id = $data['request_id'] ?? null; + $object->chat_id = $data['chat_id'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/Contact.php b/src/TgBotLib/Objects/Contact.php index 138ab01..3e8073a 100644 --- a/src/TgBotLib/Objects/Contact.php +++ b/src/TgBotLib/Objects/Contact.php @@ -111,11 +111,11 @@ { $object = new self(); - $object->phone_number = @$data['phone_number']; - $object->first_name = @$data['first_name']; - $object->last_name = @$data['last_name'] ?? null; - $object->user_id = @$data['user_id'] ?? null; - $object->vcard = @$data['vcard'] ?? null; + $object->phone_number = $data['phone_number'] ?? null; + $object->first_name = $data['first_name'] ?? null; + $object->last_name = $data['last_name'] ?? null; + $object->user_id = $data['user_id'] ?? null; + $object->vcard = $data['vcard'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/Dice.php b/src/TgBotLib/Objects/Dice.php index 5389946..fd57528 100644 --- a/src/TgBotLib/Objects/Dice.php +++ b/src/TgBotLib/Objects/Dice.php @@ -57,8 +57,8 @@ { $object = new self(); - $object->emoji = @$data['emoji'] ?? null; - $object->value = @$data['value'] ?? null; + $object->emoji = $data['emoji'] ?? null; + $object->value = $data['value'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/Document.php b/src/TgBotLib/Objects/Document.php index 9086df9..a04a871 100644 --- a/src/TgBotLib/Objects/Document.php +++ b/src/TgBotLib/Objects/Document.php @@ -111,7 +111,7 @@ return [ 'file_id' => $this->file_id ?? null, 'file_unique_id' => $this->file_unique_id ?? null, - 'thumb' => ($this->thumb instanceof PhotoSize) ? $this->thumb->toArray() : null, + 'thumb' => ($this->thumb instanceof ObjectTypeInterface) ? $this->thumb->toArray() : null, 'file_name' => $this->file_name ?? null, 'mime_type' => $this->mime_type ?? null, 'file_size' => $this->file_size ?? null, @@ -127,8 +127,8 @@ public static function fromArray(array $data): ObjectTypeInterface { $object = new self(); - $object->file_id = $data['file_id']; - $object->file_unique_id = $data['file_unique_id']; + $object->file_id = $data['file_id'] ?? null; + $object->file_unique_id = $data['file_unique_id'] ?? null; $object->thumb = isset($data['thumb']) ? PhotoSize::fromArray($data['thumb']) : null; $object->file_name = $data['file_name'] ?? null; $object->mime_type = $data['mime_type'] ?? null; diff --git a/src/TgBotLib/Objects/EncryptedCredentials.php b/src/TgBotLib/Objects/EncryptedCredentials.php index f3a7171..918d814 100644 --- a/src/TgBotLib/Objects/EncryptedCredentials.php +++ b/src/TgBotLib/Objects/EncryptedCredentials.php @@ -79,9 +79,9 @@ { $object = new self(); - $object->data = @$data['data']; - $object->hash = @$data['hash']; - $object->secret = @$data['secret']; + $object->data = $data['data'] ?? null; + $object->hash = $data['hash'] ?? null; + $object->secret = $data['secret'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/EncryptedPassportElement.php b/src/TgBotLib/Objects/EncryptedPassportElement.php index cc203d9..9f71266 100644 --- a/src/TgBotLib/Objects/EncryptedPassportElement.php +++ b/src/TgBotLib/Objects/EncryptedPassportElement.php @@ -192,27 +192,47 @@ 'data' => $this->data, 'phone_number' => $this->phone_number, 'email' => $this->email, - 'files' => array_map(function (PassportFile $file) + 'files' => is_array($this->files) ? array_map(function ($file) { - return $file->toArray(); - }, $this->files), - 'front_side' => array_map(function (PassportFile $file) + if($file instanceof PassportFile) + { + return $file->toArray(); + } + return $file; + }, $this->files) : null, + 'front_side' => is_array($this->front_side) ? array_map(function ($file) { - return $file->toArray(); - }, $this->front_side), - 'reverse_side' => array_map(function (PassportFile $file) + if($file instanceof PassportFile) + { + return $file->toArray(); + } + return $file; + }, $this->front_side) : null, + 'reverse_side' => is_array($this->reverse_side) ? array_map(function ($file) { - return $file->toArray(); - }, $this->reverse_side), - 'selfie' => array_map(function (PassportFile $file) + if($file instanceof PassportFile) + { + return $file->toArray(); + } + return $file; + }, $this->reverse_side) : null, + 'selfie' => is_array($this->selfie) ? array_map(function ($file) { - return $file->toArray(); - }, $this->selfie), - 'translation' => array_map(function (PassportFile $file) + if($file instanceof PassportFile) + { + return $file->toArray(); + } + return $file; + }, $this->selfie) : null, + 'translation' => is_array($this->translation) ? array_map(function ($file) { - return $file->toArray(); - }, $this->translation), - 'hash' => $this->hash, + if($file instanceof PassportFile) + { + return $file->toArray(); + } + return $file; + }, $this->translation) : null, + 'hash' => $this->hash ]; } @@ -230,26 +250,26 @@ $object->data = $data['data'] ?? null; $object->phone_number = $data['phone_number'] ?? null; $object->email = $data['email'] ?? null; - $object->files = array_map(function (array $file) + $object->files = isset($data['files']) ? array_map(function (array $file) { return PassportFile::fromArray($file); - }, $data['files'] ?? []); - $object->front_side = array_map(function (array $file) + }, $data['files'] ?? []) : null; + $object->front_side = isset($data['front_side']) ? array_map(function (array $file) { return PassportFile::fromArray($file); - }, $data['front_side'] ?? []); - $object->reverse_side = array_map(function (array $file) + }, $data['front_side'] ?? []) : null; + $object->reverse_side = isset($data['reverse_side']) ? array_map(function (array $file) { return PassportFile::fromArray($file); - }, $data['reverse_side'] ?? []); - $object->selfie = array_map(function (array $file) + }, $data['reverse_side'] ?? []) : null; + $object->selfie = isset($data['selfie']) ? array_map(function (array $file) { return PassportFile::fromArray($file); - }, $data['selfie'] ?? []); - $object->translation = array_map(function (array $file) + }, $data['selfie'] ?? []) : null; + $object->translation = isset($data['translation']) ? array_map(function (array $file) { return PassportFile::fromArray($file); - }, $data['translation'] ?? []); + }, $data['translation'] ?? []) : null; $object->hash = $data['hash']; return $object; diff --git a/src/TgBotLib/Objects/File.php b/src/TgBotLib/Objects/File.php index 3193ae4..7e27c35 100644 --- a/src/TgBotLib/Objects/File.php +++ b/src/TgBotLib/Objects/File.php @@ -81,8 +81,8 @@ return [ 'file_id' => $this->file_id, 'file_unique_id' => $this->file_unique_id, - 'file_size' => $this->file_size ?? null, - 'file_path' => $this->file_path ?? null, + 'file_size' => $this->file_size, + 'file_path' => $this->file_path ]; } @@ -95,10 +95,10 @@ public static function fromArray(array $data): ObjectTypeInterface { $object = new self(); - $object->file_id = @$data['file_id']; - $object->file_unique_id = @$data['file_unique_id']; - $object->file_size = @$data['file_size'] ?? null; - $object->file_path = @$data['file_path'] ?? null; + $object->file_id = $data['file_id'] ?? null; + $object->file_unique_id = $data['file_unique_id'] ?? null; + $object->file_size = $data['file_size'] ?? null; + $object->file_path = $data['file_path'] ?? null; return $object; } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/ForceReply.php b/src/TgBotLib/Objects/ForceReply.php index 9985e78..f162b1f 100644 --- a/src/TgBotLib/Objects/ForceReply.php +++ b/src/TgBotLib/Objects/ForceReply.php @@ -79,9 +79,9 @@ { $object = new self(); - $object->force_reply = $data['force_reply']; + $object->force_reply = $data['force_reply'] ?? false; $object->inline_field_placeholder = $data['inline_field_placeholder'] ?? null; - $object->selective = $data['selective']; + $object->selective = $data['selective'] ?? false; return $object; } diff --git a/src/TgBotLib/Objects/ForumTopic.php b/src/TgBotLib/Objects/ForumTopic.php index 763bd3a..dd9dd53 100644 --- a/src/TgBotLib/Objects/ForumTopic.php +++ b/src/TgBotLib/Objects/ForumTopic.php @@ -93,10 +93,10 @@ { $object = new self(); - $object->message_thread_id = $data['message_thread_id']; - $object->name = $data['name']; - $object->icon_color = $data['icon_color']; - $object->icon_custom_emoji_id = @$data['icon_custom_emoji_id'] ?: null; + $object->message_thread_id = $data['message_thread_id'] ?? null; + $object->name = $data['name'] ?? null; + $object->icon_color = $data['icon_color'] ?? null; + $object->icon_custom_emoji_id = $data['icon_custom_emoji_id'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/ForumTopicCreated.php b/src/TgBotLib/Objects/ForumTopicCreated.php index 218f737..36a5158 100644 --- a/src/TgBotLib/Objects/ForumTopicCreated.php +++ b/src/TgBotLib/Objects/ForumTopicCreated.php @@ -1,5 +1,7 @@ name = @$data['name']; - $object->icon_color = @$data['icon_color']; - $object->icon_custom_emoji_id = @$data['icon_custom_emoji_id'] ?? null; + + $object->name = $data['name'] ?? null; + $object->icon_color = $data['icon_color'] ?? null; + $object->icon_custom_emoji_id = $data['icon_custom_emoji_id'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/ForumTopicEdited.php b/src/TgBotLib/Objects/ForumTopicEdited.php index 33cca2b..3c7d5ee 100644 --- a/src/TgBotLib/Objects/ForumTopicEdited.php +++ b/src/TgBotLib/Objects/ForumTopicEdited.php @@ -62,8 +62,8 @@ { $object = new self(); - $object->name = @$data['name'] ?? null; - $object->icon_custom_emoji_id = @$data['icon_custom_emoji_id'] ?? null; + $object->name = $data['name'] ?? null; + $object->icon_custom_emoji_id = $data['icon_custom_emoji_id'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/Game.php b/src/TgBotLib/Objects/Game.php index a755bbf..d8b10d7 100644 --- a/src/TgBotLib/Objects/Game.php +++ b/src/TgBotLib/Objects/Game.php @@ -109,31 +109,17 @@ */ public function toArray(): array { - $text_entities = null; - if ($this->text_entities) - { - foreach ($this->text_entities as $text_entity) - { - $text_entities[] = $text_entity->toArray(); - } - } - - $photo = null; - if ($this->photo) - { - foreach ($this->photo as $photo_item) - { - $photo[] = $photo_item->toArray(); - } - } - return [ 'title' => $this->title, 'description' => $this->description, - 'photo' => $photo, + 'photo' => isset($this->photo) ? array_map(function ($photo) { + return $photo->toArray(); + }, $this->photo) : null, 'text' => $this->text, - 'text_entities' => $text_entities, - 'animation' => ($this->animation instanceof Animation) ? $this->animation->toArray() : null, + 'text_entities' => isset($this->text_entities) ? array_map(function ($text_entity) { + return $text_entity->toArray(); + }, $this->text_entities) : null, + 'animation' => ($this->animation instanceof ObjectTypeInterface) ? $this->animation->toArray() : null, ]; } @@ -147,28 +133,15 @@ { $object = new self(); - $photo = null; - if ($data['photo']) - { - foreach ($data['photo'] as $photo_item) - { - $photo[] = PhotoSize::fromArray($photo_item); - } - } - $text_entities = null; - if ($data['text_entities']) - { - foreach ($data['text_entities'] as $text_entity) - { - $text_entities[] = MessageEntity::fromArray($text_entity); - } - } - - $object->description = $data['description']; - $object->title = $data['title']; - $object->photo = $photo; + $object->description = $data['description'] ?? null; + $object->title = $data['title'] ?? null; + $object->photo = isset($data['photo']) && is_array($data['photo']) ? array_map(function ($photo) { + return PhotoSize::fromArray($photo); + }, $data['photo']) : null; $object->text = $data['text'] ?? null; - $object->text_entities = $text_entities; + $object->text_entities = isset($data['text_entities']) && is_array($data['text_entities']) ? array_map(function ($text_entity) { + return MessageEntity::fromArray($text_entity); + }, $data['text_entities']) : null; $object->animation = ($data['animation']) ? Animation::fromArray($data['animation']) : null; return $object; diff --git a/src/TgBotLib/Objects/InlineKeyboardButton.php b/src/TgBotLib/Objects/InlineKeyboardButton.php index 0a1b71f..d2b8dbc 100644 --- a/src/TgBotLib/Objects/InlineKeyboardButton.php +++ b/src/TgBotLib/Objects/InlineKeyboardButton.php @@ -173,11 +173,11 @@ 'text' => $this->text ?? null, 'url' => $this->url ?? null, 'callback_data' => $this->callback_data ?? null, - 'web_app' => ($this->web_app instanceof WebAppInfo) ? $this->web_app->toArray() : null, - 'login_url' => ($this->login_url instanceof LoginUrl) ? $this->login_url->toArray() : null, + 'web_app' => ($this->web_app instanceof ObjectTypeInterface) ? $this->web_app->toArray() : null, + 'login_url' => ($this->login_url instanceof ObjectTypeInterface) ? $this->login_url->toArray() : null, 'switch_inline_query' => $this->switch_inline_query ?? null, 'switch_inline_query_current_chat' => $this->switch_inline_query_current_chat ?? null, - 'callback_game' => ($this->callback_game instanceof CallbackGame) ? $this->callback_game->toArray() : null, + 'callback_game' => ($this->callback_game instanceof ObjectTypeInterface) ? $this->callback_game->toArray() : null, 'pay' => $this->pay ?? null ]; } @@ -195,11 +195,11 @@ $object->text = $data['text'] ?? null; $object->url = $data['url'] ?? null; $object->callback_data = $data['callback_data'] ?? null; - $object->web_app = ($data['web_app'] ?? null) ? WebAppInfo::fromArray($data['web_app']) : null; - $object->login_url = ($data['login_url'] ?? null) ? LoginUrl::fromArray($data['login_url']) : null; + $object->web_app = isset($data['web_app']) && is_array($data['web_app']) ? WebAppInfo::fromArray($data['web_app']) : null; + $object->login_url = isset($data['login_url']) && is_array($data['login_url']) ? LoginUrl::fromArray($data['login_url']) : null; $object->switch_inline_query = $data['switch_inline_query'] ?? null; $object->switch_inline_query_current_chat = $data['switch_inline_query_current_chat'] ?? null; - $object->callback_game = ($data['callback_game'] ?? null) ? CallbackGame::fromArray($data['callback_game']) : null; + $object->callback_game = isset($data['callback_game']) && is_array($data['callback_game']) ? CallbackGame::fromArray($data['callback_game']) : null; $object->pay = $data['pay'] ?? null; return $object; diff --git a/src/TgBotLib/Objects/InlineKeyboardMarkup.php b/src/TgBotLib/Objects/InlineKeyboardMarkup.php index a8bcdf5..5df9493 100644 --- a/src/TgBotLib/Objects/InlineKeyboardMarkup.php +++ b/src/TgBotLib/Objects/InlineKeyboardMarkup.php @@ -27,13 +27,22 @@ /** * Returns an array representation of the object * - * @return InlineKeyboardButton[][][] + * @return array[][] */ public function toArray(): array { - return [ - 'inline_keyboard' => $this->inline_keyboard, - ]; + $data = []; + + if ($this->inline_keyboard !== null) + { + /** @var InlineKeyboardButton $item */ + foreach ($this->inline_keyboard as $item) + { + $data[][] = $item->toArray(); + } + } + + return $data; } /** @@ -45,7 +54,14 @@ public static function fromArray(array $data): ObjectTypeInterface { $object = new self(); - $object->inline_keyboard = @$data['inline_keyboard'] ?? null; + + $object->inline_keyboard = []; + + foreach($data as $item) + { + $object->inline_keyboard[] = InlineKeyboardButton::fromArray($item); + } + return $object; } diff --git a/src/TgBotLib/Objects/InputMedia.php b/src/TgBotLib/Objects/InputMedia.php index 85e486d..0e07b43 100644 --- a/src/TgBotLib/Objects/InputMedia.php +++ b/src/TgBotLib/Objects/InputMedia.php @@ -212,7 +212,7 @@ * * @return bool */ - public function isHasSpoiler(): bool + public function hasSpoiler(): bool { return $this->has_spoiler; } @@ -235,23 +235,15 @@ */ public function toArray(): array { - $caption_entities = null; - if($this->caption_entities !== null) - { - $caption_entities = []; - foreach($this->caption_entities as $entity) - { - $caption_entities[] = $entity->toArray(); - } - } - return [ 'type' => $this->type, 'media' => $this->media, 'thumb' => $this->thumb, 'caption' => $this->caption, 'parse_mode' => $this->parse_mode, - 'caption_entities' => $caption_entities, + 'caption_entities' => is_array($this->caption_entities) ? array_map(function($entity) { + return $entity->toArray(); + }, $this->caption_entities) : null, 'width' => $this->width, 'height' => $this->height, 'duration' => $this->duration, @@ -271,31 +263,24 @@ */ public static function fromArray(array $data): ObjectTypeInterface { - $caption_entities = null; - if($data['caption_entities'] !== null) - { - $caption_entities = []; - foreach($data['caption_entities'] as $entity) - { - $caption_entities[] = MessageEntity::fromArray($entity); - } - } - $object = new self(); - $object->type = $data['type']; - $object->media = $data['media']; - $object->thumb = @$data['thumb'] ?? null; - $object->caption = @$data['caption'] ?? null; - $object->parse_mode = @$data['parse_mode'] ?? null; - $object->caption_entities = $caption_entities; - $object->width = @$data['width'] ?? null; - $object->height = @$data['height'] ?? null; - $object->duration = @$data['duration'] ?? null; - $object->performer = @$data['performer'] ?? null; - $object->title = @$data['title'] ?? null; - $object->supports_streaming = @$data['supports_streaming'] ?? false; - $object->has_spoiler = @$data['has_spoiler'] ?? false; - $object->disable_content_type_detection = @$data['disable_content_type_detection'] ?? false; + $object->type = $data['type'] ?? null; + $object->media = $data['media'] ?? null; + $object->thumb = $data['thumb'] ?? null; + $object->caption = $data['caption'] ?? null; + $object->parse_mode = $data['parse_mode'] ?? null; + $object->caption_entities = isset($data['caption_entities']) && is_array($data['caption_entities']) ? array_map(function($entity) + { + return MessageEntity::fromArray($entity); + }, $data['caption_entities']) : null; + $object->width = $data['width'] ?? null; + $object->height = $data['height'] ?? null; + $object->duration = $data['duration'] ?? null; + $object->performer = $data['performer'] ?? null; + $object->title = $data['title'] ?? null; + $object->supports_streaming = $data['supports_streaming'] ?? false; + $object->has_spoiler = $data['has_spoiler'] ?? false; + $object->disable_content_type_detection = $data['disable_content_type_detection'] ?? false; return $object; } diff --git a/src/TgBotLib/Objects/InputMedia/InputMediaAnimation.php b/src/TgBotLib/Objects/InputMedia/InputMediaAnimation.php index 3b17727..1d2b017 100644 --- a/src/TgBotLib/Objects/InputMedia/InputMediaAnimation.php +++ b/src/TgBotLib/Objects/InputMedia/InputMediaAnimation.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\InputMedia; + use TgBotLib\Abstracts\InputMediaType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\InputMedia; use TgBotLib\Objects\MessageEntity; @@ -61,6 +62,8 @@ private $has_spoiler; /** + * Type of the result, must be animation + * * @return string */ public function getType(): string @@ -163,7 +166,7 @@ * * @return bool */ - public function isHasSpoiler(): bool + public function hasSpoiler(): bool { return $this->has_spoiler; } @@ -175,23 +178,19 @@ */ public function toArray(): array { - $caption_entities = null; - if ($this->caption_entities) - { - $caption_entities = []; - foreach ($this->caption_entities as $caption_entity) - { - $caption_entities[] = $caption_entity->toArray(); - } - } - return [ 'type' => $this->type, 'media' => $this->media, 'thumb' => $this->thumb, 'caption' => $this->caption, 'parse_mode' => $this->parse_mode, - 'caption_entities' => $caption_entities, + 'caption_entities' => is_array($this->caption_entities) ? array_map(function ($item) { + if($item instanceof ObjectTypeInterface) + { + return $item->toArray(); + } + return $item; + }, $this->caption_entities) : null, 'width' => $this->width, 'height' => $this->height, 'duration' => $this->duration, @@ -204,30 +203,24 @@ * * @param array $data * @return ObjectTypeInterface + * @noinspection DuplicatedCode */ public static function fromArray(array $data): ObjectTypeInterface { - $caption_entities = null; - if ($data['caption_entities']) - { - $caption_entities = []; - foreach ($data['caption_entities'] as $caption_entity) - { - $caption_entities[] = MessageEntity::fromArray($caption_entity); - } - } - $object = new static(); - $object->type = $data['type']; - $object->media = $data['media']; - $object->thumb = $data['thumb']; - $object->caption = $data['caption']; - $object->parse_mode = $data['parse_mode']; - $object->caption_entities = $caption_entities; - $object->width = $data['width']; - $object->height = $data['height']; - $object->duration = $data['duration']; - $object->has_spoiler = $data['has_spoiler']; + $object->type = $data['type'] ?? InputMediaType::Animation; + $object->media = $data['media'] ?? null; + $object->thumb = $data['thumb'] ?? null; + $object->caption = $data['caption'] ?? null; + $object->parse_mode = $data['parse_mode'] ?? null; + $object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item) + { + return MessageEntity::fromArray($item); + }, $data['caption_entities']) : null; + $object->width = $data['width'] ?? null; + $object->height = $data['height'] ?? null; + $object->duration = $data['duration'] ?? null; + $object->has_spoiler = $data['has_spoiler'] ?? false; return $object; } @@ -237,6 +230,7 @@ * * @param InputMedia $inputMedia * @return InputMediaAnimation + * @noinspection DuplicatedCode */ public static function fromInputMedia(InputMedia $inputMedia): InputMediaAnimation { @@ -251,7 +245,7 @@ $object->width = $inputMedia->getWidth(); $object->height = $inputMedia->getHeight(); $object->duration = $inputMedia->getDuration(); - $object->has_spoiler = $inputMedia->isHasSpoiler(); + $object->has_spoiler = $inputMedia->hasSpoiler(); return $object; } diff --git a/src/TgBotLib/Objects/InputMedia/InputMediaAudio.php b/src/TgBotLib/Objects/InputMedia/InputMediaAudio.php index b8f4a93..11a2294 100644 --- a/src/TgBotLib/Objects/InputMedia/InputMediaAudio.php +++ b/src/TgBotLib/Objects/InputMedia/InputMediaAudio.php @@ -160,23 +160,19 @@ */ public function toArray(): array { - $caption_entities = null; - if ($this->caption_entities) - { - $caption_entities = []; - foreach ($this->caption_entities as $caption_entity) - { - $caption_entities[] = $caption_entity->toArray(); - } - } - return [ 'type' => $this->type, 'media' => $this->media, 'thumb' => $this->thumb, 'caption' => $this->caption, 'parse_mode' => $this->parse_mode, - 'caption_entities' => $caption_entities, + 'caption_entities' => is_array($this->caption_entities) ? array_map(function ($item) { + if($item instanceof ObjectTypeInterface) + { + return $item->toArray(); + } + return $item; + }, $this->caption_entities) : null, 'duration' => $this->duration, 'performer' => $this->performer, 'title' => $this->title @@ -188,29 +184,24 @@ * * @param array $data * @return ObjectTypeInterface + * @noinspection DuplicatedCode */ public static function fromArray(array $data): ObjectTypeInterface { - $caption_entities = null; - if ($data['caption_entities']) - { - $caption_entities = []; - foreach ($data['caption_entities'] as $caption_entity) - { - $caption_entities[] = MessageEntity::fromArray($caption_entity); - } - } $object = new InputMediaAudio(); - $object->type = $data['type']; - $object->media = $data['media']; - $object->thumb = $data['thumb']; - $object->caption = $data['caption']; - $object->parse_mode = $data['parse_mode']; - $object->caption_entities = $caption_entities; - $object->duration = $data['duration']; - $object->performer = $data['performer']; - $object->title = $data['title']; + $object->type = $data['type'] ?? null; + $object->media = $data['media'] ?? null; + $object->thumb = $data['thumb'] ?? null; + $object->caption = $data['caption'] ?? null; + $object->parse_mode = $data['parse_mode'] ?? null; + $object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item) + { + return MessageEntity::fromArray($item); + }, $data['caption_entities']) : null; + $object->duration = $data['duration'] ?? null; + $object->performer = $data['performer'] ?? null; + $object->title = $data['title'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/InputMedia/InputMediaDocument.php b/src/TgBotLib/Objects/InputMedia/InputMediaDocument.php index 12b66c2..60d0e96 100644 --- a/src/TgBotLib/Objects/InputMedia/InputMediaDocument.php +++ b/src/TgBotLib/Objects/InputMedia/InputMediaDocument.php @@ -132,23 +132,19 @@ */ public function toArray(): array { - $caption_entities = null; - if ($this->caption_entities) - { - $caption_entities = []; - foreach ($this->caption_entities as $caption_entity) - { - $caption_entities[] = $caption_entity->toArray(); - } - } - return [ 'type' => $this->type, 'media' => $this->media, 'thumb' => $this->thumb, 'caption' => $this->caption, 'parse_mode' => $this->parse_mode, - 'caption_entities' => $caption_entities, + 'caption_entities' => is_array($this->caption_entities) ? array_map(function ($item) { + if($item instanceof ObjectTypeInterface) + { + return $item->toArray(); + } + return $item; + }, $this->caption_entities) : null, 'disable_content_type_detection' => $this->disable_content_type_detection, ]; } @@ -158,27 +154,21 @@ * * @param array $data * @return ObjectTypeInterface + * @noinspection DuplicatedCode */ public static function fromArray(array $data): ObjectTypeInterface { - $caption_entities = null; - if (isset($data['caption_entities'])) - { - $caption_entities = []; - foreach ($data['caption_entities'] as $caption_entity) - { - $caption_entities[] = MessageEntity::fromArray($caption_entity); - } - } - $object = new InputMediaDocument(); - $object->type = $data['type']; - $object->media = $data['media']; + $object->type = $data['type'] ?? null; + $object->media = $data['media'] ?? null; $object->thumb = $data['thumb'] ?? null; $object->caption = $data['caption'] ?? null; $object->parse_mode = $data['parse_mode'] ?? null; - $object->caption_entities = $caption_entities; - $object->disable_content_type_detection = $data['disable_content_type_detection']; + $object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item) + { + return MessageEntity::fromArray($item); + }, $data['caption_entities']) : null; + $object->disable_content_type_detection = $data['disable_content_type_detection'] ?? false; return $object; } @@ -192,6 +182,7 @@ public static function fromInputMedia(InputMedia $inputMedia): InputMediaDocument { $object = new InputMediaDocument(); + $object->type = $inputMedia->getType(); $object->media = $inputMedia->getMedia(); $object->thumb = $inputMedia->getThumb(); diff --git a/src/TgBotLib/Objects/InputMedia/InputMediaPhoto.php b/src/TgBotLib/Objects/InputMedia/InputMediaPhoto.php index 64863ea..c0feee2 100644 --- a/src/TgBotLib/Objects/InputMedia/InputMediaPhoto.php +++ b/src/TgBotLib/Objects/InputMedia/InputMediaPhoto.php @@ -99,7 +99,7 @@ * * @return bool */ - public function isHasSpoiler(): bool + public function hasSpoiler(): bool { return $this->has_spoiler; } @@ -111,22 +111,18 @@ */ public function toArray(): array { - $caption_entities = null; - if ($this->caption_entities) - { - $caption_entities = []; - foreach ($this->caption_entities as $caption_entity) - { - $caption_entities[] = $caption_entity->toArray(); - } - } - return [ 'type' => $this->type, 'media' => $this->media, 'caption' => $this->caption, 'parse_mode' => $this->parse_mode, - 'caption_entities' => $caption_entities, + 'caption_entities' => is_array($this->caption_entities) ? array_map(function ($item) { + if($item instanceof ObjectTypeInterface) + { + return $item->toArray(); + } + return $item; + }, $this->caption_entities) : null, 'has_spoiler' => $this->has_spoiler, ]; } @@ -141,20 +137,15 @@ { $object = new self(); - $object->type = $data['type']; - $object->media = $data['media']; - $object->caption = $data['caption']; - $object->parse_mode = $data['parse_mode']; - $object->has_spoiler = $data['has_spoiler']; - - if (isset($data['caption_entities'])) + $object->type = $data['type'] ?? null; + $object->media = $data['media'] ?? null; + $object->caption = $data['caption'] ?? null; + $object->parse_mode = $data['parse_mode'] ?? null; + $object->has_spoiler = $data['has_spoiler'] ?? null; + $object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item) { - $object->caption_entities = []; - foreach ($data['caption_entities'] as $caption_entity) - { - $object->caption_entities[] = MessageEntity::fromArray($caption_entity); - } - } + return MessageEntity::fromArray($item); + }, $data['caption_entities']) : null; return $object; } @@ -173,16 +164,8 @@ $object->media = $inputMedia->getMedia(); $object->caption = $inputMedia->getCaption(); $object->parse_mode = $inputMedia->getParseMode(); - $object->has_spoiler = $inputMedia->isHasSpoiler(); - - if ($inputMedia->getCaptionEntities()) - { - $object->caption_entities = []; - foreach ($inputMedia->getCaptionEntities() as $caption_entity) - { - $object->caption_entities[] = MessageEntity::fromArray($caption_entity); - } - } + $object->has_spoiler = $inputMedia->hasSpoiler(); + $object->caption_entities = $inputMedia->getCaptionEntities(); return $object; } diff --git a/src/TgBotLib/Objects/InputMedia/InputMediaVideo.php b/src/TgBotLib/Objects/InputMedia/InputMediaVideo.php index 53bd21c..c83785a 100644 --- a/src/TgBotLib/Objects/InputMedia/InputMediaVideo.php +++ b/src/TgBotLib/Objects/InputMedia/InputMediaVideo.php @@ -169,7 +169,7 @@ * * @return bool */ - public function isSupportsStreaming(): bool + public function supportsStreaming(): bool { return $this->supports_streaming; } @@ -179,7 +179,7 @@ * * @return bool */ - public function isHasSpoiler(): bool + public function hasSpoiler(): bool { return $this->has_spoiler; } @@ -191,23 +191,19 @@ */ public function toArray(): array { - $caption_entities = null; - if($this->getCaptionEntities() !== null) - { - $caption_entities = []; - foreach ($this->getCaptionEntities() as $caption_entity) - { - $caption_entities[] = $caption_entity->toArray(); - } - } - return [ 'type' => $this->type, 'media' => $this->media, 'thumb' => $this->thumb, 'caption' => $this->caption, 'parse_mode' => $this->parse_mode, - 'caption_entities' => $caption_entities, + 'caption_entities' => is_array($this->caption_entities) ? array_map(function ($item) { + if($item instanceof ObjectTypeInterface) + { + return $item->toArray(); + } + return $item; + }, $this->caption_entities) : null, 'width' => $this->width, 'height' => $this->height, 'duration' => $this->duration, @@ -221,32 +217,26 @@ * * @param array $data * @return ObjectTypeInterface + * @noinspection DuplicatedCode */ public static function fromArray(array $data): ObjectTypeInterface { - $caption_entities = null; - if($data['caption_entities'] !== null) - { - $caption_entities = []; - foreach ($data['caption_entities'] as $caption_entity) - { - $caption_entities[] = MessageEntity::fromArray($caption_entity); - } - } - $object = new InputMediaVideo(); - $object->type = $data['type']; - $object->media = $data['media']; - $object->thumb = @$data['thumb'] ?? null; - $object->caption = @$data['caption'] ?? null; - $object->parse_mode = @$data['parse_mode'] ?? null; - $object->caption_entities = $caption_entities; - $object->width = @$data['width'] ?? null; - $object->height = @$data['height'] ?? null; - $object->duration = @$data['duration'] ?? null; - $object->supports_streaming = @$data['supports_streaming'] ?? false; - $object->has_spoiler = @$data['has_spoiler'] ?? false; + $object->type = $data['type'] ?? null; + $object->media = $data['media'] ?? null; + $object->thumb = $data['thumb'] ?? null; + $object->caption = $data['caption'] ?? null; + $object->parse_mode = $data['parse_mode'] ?? null; + $object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item) + { + return MessageEntity::fromArray($item); + }, $data['caption_entities']) : null; + $object->width = $data['width'] ?? null; + $object->height = $data['height'] ?? null; + $object->duration = $data['duration'] ?? null; + $object->supports_streaming = $data['supports_streaming'] ?? false; + $object->has_spoiler = $data['has_spoiler'] ?? false; return $object; } @@ -256,6 +246,7 @@ * * @param InputMedia $inputMedia * @return InputMediaVideo + * @noinspection DuplicatedCode */ public static function fromInputMedia(InputMedia $inputMedia): InputMediaVideo { @@ -271,7 +262,7 @@ $object->height = $inputMedia->getHeight(); $object->duration = $inputMedia->getDuration(); $object->supports_streaming = $inputMedia->isSupportsStreaming(); - $object->has_spoiler = $inputMedia->isHasSpoiler(); + $object->has_spoiler = $inputMedia->hasSpoiler(); return $object; } diff --git a/src/TgBotLib/Objects/Invoice.php b/src/TgBotLib/Objects/Invoice.php index b3a09a8..334545b 100644 --- a/src/TgBotLib/Objects/Invoice.php +++ b/src/TgBotLib/Objects/Invoice.php @@ -113,11 +113,11 @@ { $object = new self(); - $object->title = $data['title']; - $object->description = $data['description']; - $object->start_parameter = $data['start_parameter']; - $object->currency = $data['currency']; - $object->total_amount = $data['total_amount']; + $object->title = $data['title'] ?? null; + $object->description = $data['description'] ?? null; + $object->start_parameter = $data['start_parameter'] ?? null; + $object->currency = $data['currency'] ?? null; + $object->total_amount = $data['total_amount'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/KeyboardButton.php b/src/TgBotLib/Objects/KeyboardButton.php index a14ac30..e35419b 100644 --- a/src/TgBotLib/Objects/KeyboardButton.php +++ b/src/TgBotLib/Objects/KeyboardButton.php @@ -130,12 +130,12 @@ { return [ 'text' => $this->text, - 'request_user' => ($this->request_user instanceof KeyboardButtonRequestUser) ? $this->request_user->toArray() : null, - 'request_chat' => ($this->request_chat instanceof KeyboardButtonRequestChat) ? $this->request_chat->toArray() : null, + 'request_user' => ($this->request_user instanceof ObjectTypeInterface) ? $this->request_user->toArray() : null, + 'request_chat' => ($this->request_chat instanceof ObjectTypeInterface) ? $this->request_chat->toArray() : null, 'request_contact' => $this->request_contact, 'request_location' => $this->request_location, - 'request_poll' => ($this->request_poll instanceof KeyboardButtonPollType) ? $this->request_poll->toArray() : null, - 'web_app' => ($this->web_app instanceof WebAppInfo) ? $this->web_app->toArray() : null, + 'request_poll' => ($this->request_poll instanceof ObjectTypeInterface) ? $this->request_poll->toArray() : null, + 'web_app' => ($this->web_app instanceof ObjectTypeInterface) ? $this->web_app->toArray() : null, ]; } @@ -149,11 +149,11 @@ { $object = new self(); - $object->text = $data['text']; + $object->text = $data['text'] ?? null; $object->request_user = isset($data['request_user']) ? KeyboardButtonRequestUser::fromArray($data['request_user']) : null; $object->request_chat = isset($data['request_chat']) ? KeyboardButtonRequestChat::fromArray($data['request_chat']) : null; - $object->request_contact = $data['request_contact']; - $object->request_location = $data['request_location']; + $object->request_contact = $data['request_contact'] ?? null; + $object->request_location = $data['request_location'] ?? null; $object->request_poll = isset($data['request_poll']) ? KeyboardButtonPollType::fromArray($data['request_poll']) : null; $object->web_app = isset($data['web_app']) ? WebAppInfo::fromArray($data['web_app']) : null; diff --git a/src/TgBotLib/Objects/KeyboardButtonPollType.php b/src/TgBotLib/Objects/KeyboardButtonPollType.php index da48a54..1e6f7c7 100644 --- a/src/TgBotLib/Objects/KeyboardButtonPollType.php +++ b/src/TgBotLib/Objects/KeyboardButtonPollType.php @@ -1,5 +1,7 @@ type = @$data['type'] ?? null; + + $object->type = $data['type'] ?? null; + return $object; } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/KeyboardButtonRequestChat.php b/src/TgBotLib/Objects/KeyboardButtonRequestChat.php index 96fe54a..2431318 100644 --- a/src/TgBotLib/Objects/KeyboardButtonRequestChat.php +++ b/src/TgBotLib/Objects/KeyboardButtonRequestChat.php @@ -65,7 +65,7 @@ * * @return bool */ - public function isChatIsChannel(): bool + public function chatIsChannel(): bool { return $this->chat_is_channel; } @@ -76,7 +76,7 @@ * * @return bool */ - public function isChatIsForum(): bool + public function chatIsForum(): bool { return $this->chat_is_forum; } @@ -87,7 +87,7 @@ * * @return bool */ - public function isChatHasUsername(): bool + public function chatHasUsername(): bool { return $this->chat_has_username; } @@ -97,7 +97,7 @@ * * @return bool */ - public function isChatIsCreated(): bool + public function chatIsCreated(): bool { return $this->chat_is_created; } @@ -132,7 +132,7 @@ * * @return bool */ - public function isBotIsMember(): bool + public function botIsMember(): bool { return $this->bot_is_member; } @@ -150,8 +150,8 @@ 'chat_is_forum' => $this->chat_is_forum, 'chat_has_username' => $this->chat_has_username, 'chat_is_created' => $this->chat_is_created, - 'user_administrator_rights' => ($this->user_administrator_rights instanceof ChatAdministratorRights) ? $this->user_administrator_rights->toArray() : null, - 'bot_administrator_rights' => ($this->bot_administrator_rights instanceof ChatAdministratorRights) ? $this->bot_administrator_rights->toArray() : null, + 'user_administrator_rights' => ($this->user_administrator_rights instanceof ObjectTypeInterface) ? $this->user_administrator_rights->toArray() : null, + 'bot_administrator_rights' => ($this->bot_administrator_rights instanceof ObjectTypeInterface) ? $this->bot_administrator_rights->toArray() : null, 'bot_is_member' => $this->bot_is_member, ]; } @@ -166,14 +166,14 @@ { $object = new self(); - $object->request_id = $data['request_id']; - $object->chat_is_channel = $data['chat_is_channel']; - $object->chat_is_forum = $data['chat_is_forum']; - $object->chat_has_username = $data['chat_has_username']; - $object->chat_is_created = $data['chat_is_created']; + $object->request_id = $data['request_id'] ?? null; + $object->chat_is_channel = $data['chat_is_channel'] ?? false; + $object->chat_is_forum = $data['chat_is_forum'] ?? false; + $object->chat_has_username = $data['chat_has_username'] ?? false; + $object->chat_is_created = $data['chat_is_created'] ?? false; $object->user_administrator_rights = ($data['user_administrator_rights'] !== null) ? ChatAdministratorRights::fromArray($data['user_administrator_rights']) : null; $object->bot_administrator_rights = ($data['bot_administrator_rights'] !== null) ? ChatAdministratorRights::fromArray($data['bot_administrator_rights']) : null; - $object->bot_is_member = $data['bot_is_member']; + $object->bot_is_member = $data['bot_is_member'] ?? false; return $object; } diff --git a/src/TgBotLib/Objects/KeyboardButtonRequestUser.php b/src/TgBotLib/Objects/KeyboardButtonRequestUser.php index 2b7c486..8e9a1bc 100644 --- a/src/TgBotLib/Objects/KeyboardButtonRequestUser.php +++ b/src/TgBotLib/Objects/KeyboardButtonRequestUser.php @@ -81,9 +81,9 @@ { $object = new self(); - $object->request_id = $data['request_id']; - $object->user_is_bot = $data['user_is_bot']; - $object->user_is_premium = $data['user_is_premium']; + $object->request_id = $data['request_id'] ?? null; + $object->user_is_bot = $data['user_is_bot'] ?? false; + $object->user_is_premium = $data['user_is_premium'] ?? false; return $object; } diff --git a/src/TgBotLib/Objects/LabeledPrice.php b/src/TgBotLib/Objects/LabeledPrice.php index ae52a16..2f3ec51 100644 --- a/src/TgBotLib/Objects/LabeledPrice.php +++ b/src/TgBotLib/Objects/LabeledPrice.php @@ -65,8 +65,8 @@ { $object = new self(); - $object->label = $data['label']; - $object->amount = $data['amount']; + $object->label = $data['label'] ?? null; + $object->amount = $data['amount'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/Location.php b/src/TgBotLib/Objects/Location.php index a0b0c31..fbbda69 100644 --- a/src/TgBotLib/Objects/Location.php +++ b/src/TgBotLib/Objects/Location.php @@ -127,12 +127,12 @@ { $object = new self(); - $object->longitude = $data['longitude']; - $object->latitude = $data['latitude']; - $object->horizontal_accuracy = $data['horizontal_accuracy']; - $object->live_period = $data['live_period']; - $object->heading = $data['heading']; - $object->proximity_alert_radius = $data['proximity_alert_radius']; + $object->longitude = $data['longitude'] ?? null; + $object->latitude = $data['latitude'] ?? null; + $object->horizontal_accuracy = $data['horizontal_accuracy'] ?? null; + $object->live_period = $data['live_period'] ?? null; + $object->heading = $data['heading'] ?? null; + $object->proximity_alert_radius = $data['proximity_alert_radius'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/LoginUrl.php b/src/TgBotLib/Objects/LoginUrl.php index 23a112e..3b722f2 100644 --- a/src/TgBotLib/Objects/LoginUrl.php +++ b/src/TgBotLib/Objects/LoginUrl.php @@ -100,7 +100,7 @@ { $object = new self(); - $object->url = $data['url']; + $object->url = $data['url'] ?? null; $object->forward_text = $data['forward_text'] ?? null; $object->bot_username = $data['bot_username'] ?? null; $object->request_write_access = $data['request_write_access'] ?? false; diff --git a/src/TgBotLib/Objects/MaskPosition.php b/src/TgBotLib/Objects/MaskPosition.php index 260a50c..131df01 100644 --- a/src/TgBotLib/Objects/MaskPosition.php +++ b/src/TgBotLib/Objects/MaskPosition.php @@ -96,10 +96,10 @@ { $object = new self(); - $object->point = $data['point']; - $object->x_shift = $data['x_shift']; - $object->y_shift = $data['y_shift']; - $object->scale = $data['scale']; + $object->point = $data['point'] ?? null; + $object->x_shift = $data['x_shift'] ?? null; + $object->y_shift = $data['y_shift'] ?? null; + $object->scale = $data['scale'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/MenuButton.php b/src/TgBotLib/Objects/MenuButton.php index 41c022e..4d4fee1 100644 --- a/src/TgBotLib/Objects/MenuButton.php +++ b/src/TgBotLib/Objects/MenuButton.php @@ -64,7 +64,7 @@ return [ 'type' => $this->type, 'text' => $this->text, - 'web_app' => ($this->web_app instanceof WebAppInfo) ? $this->web_app->toArray() : null + 'web_app' => ($this->web_app instanceof ObjectTypeInterface) ? $this->web_app->toArray() : null ]; } @@ -78,7 +78,7 @@ { $object = new self(); - $object->type = $data['type']; + $object->type = $data['type'] ?? null; $object->text = $data['text'] ?? null; $object->web_app = ($data['web_app'] ?? null) ? WebAppInfo::fromArray($data['web_app']) : null; diff --git a/src/TgBotLib/Objects/MenuButton/MenuButtonCommands.php b/src/TgBotLib/Objects/MenuButton/MenuButtonCommands.php index 192395c..403232d 100644 --- a/src/TgBotLib/Objects/MenuButton/MenuButtonCommands.php +++ b/src/TgBotLib/Objects/MenuButton/MenuButtonCommands.php @@ -46,7 +46,7 @@ { $object = new self(); - $object->type = $data['type']; + $object->type = $data['type'] ?? null; return $object; } @@ -60,7 +60,9 @@ public static function fromMenuButton(MenuButton $menuButton): MenuButtonCommands { $object = new self(); + $object->type = $menuButton->getType(); + return $object; } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/MenuButton/MenuButtonDefault.php b/src/TgBotLib/Objects/MenuButton/MenuButtonDefault.php index 97d4b04..8384878 100644 --- a/src/TgBotLib/Objects/MenuButton/MenuButtonDefault.php +++ b/src/TgBotLib/Objects/MenuButton/MenuButtonDefault.php @@ -46,7 +46,7 @@ { $object = new self(); - $object->type = $data['type']; + $object->type = $data['type'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/MenuButton/MenuButtonWebApp.php b/src/TgBotLib/Objects/MenuButton/MenuButtonWebApp.php index 449fe12..1d64ea8 100644 --- a/src/TgBotLib/Objects/MenuButton/MenuButtonWebApp.php +++ b/src/TgBotLib/Objects/MenuButton/MenuButtonWebApp.php @@ -1,6 +1,8 @@ - $this->type, 'text' => $this->text, - 'web_app' => ($this->web_app instanceof WebAppInfo) ? $this->web_app->toArray() : null + 'web_app' => ($this->web_app instanceof ObjectTypeInterface) ? $this->web_app->toArray() : null ]; } @@ -79,8 +81,8 @@ namespace TgBotLib\Objects\MenuButton; { $object = new self(); - $object->type = $data['type']; - $object->text = $data['text']; + $object->type = $data['type'] ?? null; + $object->text = $data['text'] ?? null; $object->web_app = isset($data['web_app']) ? WebAppInfo::fromArray($data['web_app']) : null; return $object; diff --git a/src/TgBotLib/Objects/Message.php b/src/TgBotLib/Objects/Message.php index 2184d42..a2aecf1 100644 --- a/src/TgBotLib/Objects/Message.php +++ b/src/TgBotLib/Objects/Message.php @@ -496,7 +496,7 @@ * * @return bool */ - public function isIsTopicMessage(): bool + public function isTopicMessage(): bool { return $this->is_topic_message; } @@ -548,7 +548,7 @@ * * @return bool */ - public function isHasProtectedContent(): bool + public function hasProtectedContent(): bool { return $this->has_protected_content; } @@ -703,7 +703,7 @@ * * @return bool */ - public function isHasMediaSpoiler(): bool + public function hasMediaSpoiler(): bool { return $this->has_media_spoiler; } @@ -1113,125 +1113,107 @@ */ public function toArray(): array { - $entities = null; - if($this->entities !== null) - { - $entities = []; - foreach($this->entities as $entity) - { - $entities[] = $entity->toArray(); - } - } - - $photo = null; - if($this->photo !== null) - { - $photo = []; - foreach($this->photo as $photo_size) - { - $photo[] = $photo_size->toArray(); - } - } - - $caption_entities = null; - if($this->caption_entities !== null) - { - $caption_entities = []; - foreach($this->caption_entities as $caption_entity) - { - $caption_entities[] = $caption_entity->toArray(); - } - } - - $new_chat_members = []; - if($this->new_chat_members !== null) - { - foreach($this->new_chat_members as $new_chat_member) - { - $new_chat_members[] = $new_chat_member->toArray(); - } - } - - $new_chat_photo = []; - if($this->new_chat_photo !== null) - { - foreach($this->new_chat_photo as $new_chat_photo_size) - { - $new_chat_photo[] = $new_chat_photo_size->toArray(); - } - } - return [ 'message_id' => $this->message_id, 'message_thread_id' => $this->message_thread_id, - 'from' => ($this->from instanceof User) ? $this->from->toArray() : null, - 'sender_chat' => ($this->sender_chat instanceof Chat) ? $this->sender_chat->toArray() : null, + 'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : null, + 'sender_chat' => ($this->sender_chat instanceof ObjectTypeInterface) ? $this->sender_chat->toArray() : null, 'date' => $this->date, - 'chat' => ($this->chat instanceof Chat) ? $this->chat->toArray() : null, - 'forward_from' => ($this->forward_from instanceof User) ? $this->forward_from->toArray() : null, - 'forward_from_chat' => ($this->forward_from_chat instanceof Chat) ? $this->forward_from_chat->toArray() : null, + 'chat' => ($this->chat instanceof ObjectTypeInterface) ? $this->chat->toArray() : null, + 'forward_from' => ($this->forward_from instanceof ObjectTypeInterface) ? $this->forward_from->toArray() : null, + 'forward_from_chat' => ($this->forward_from_chat instanceof ObjectTypeInterface) ? $this->forward_from_chat->toArray() : null, 'forward_from_message_id' => $this->forward_from_message_id, 'forward_signature' => $this->forward_signature, 'forward_sender_name' => $this->forward_sender_name, 'forward_date' => $this->forward_date, 'is_topic_message' => $this->is_topic_message, 'is_automatic_forward' => $this->is_automatic_forward, - 'reply_to_message' => ($this->reply_to_message instanceof Message) ? $this->reply_to_message->toArray() : null, - 'via_bot' => ($this->via_bot instanceof User) ? $this->via_bot->toArray() : null, + 'reply_to_message' => ($this->reply_to_message instanceof ObjectTypeInterface) ? $this->reply_to_message->toArray() : null, + 'via_bot' => ($this->via_bot instanceof ObjectTypeInterface) ? $this->via_bot->toArray() : null, 'edit_date' => $this->edit_date, 'has_protected_content' => $this->has_protected_content, 'media_group_id' => $this->media_group_id, 'author_signature' => $this->author_signature, 'text' => $this->text, - 'entities' => $entities, - 'animation' => ($this->animation instanceof Animation) ? $this->animation->toArray() : null, - 'audio' => ($this->audio instanceof Audio) ? $this->audio->toArray() : null, - 'document' => ($this->document instanceof Document) ? $this->document->toArray() : null, - 'photo' => $photo, - 'sticker' => ($this->sticker instanceof Sticker) ? $this->sticker->toArray() : null, - 'video' => ($this->video instanceof Video) ? $this->video->toArray() : null, - 'video_note' => ($this->video_note instanceof VideoNote) ? $this->video_note->toArray() : null, - 'voice' => ($this->voice instanceof Voice) ? $this->voice->toArray() : null, + 'entities' => is_array($this->entities) ? array_map(function ($entity) { + if ($entity instanceof ObjectTypeInterface) + { + return $entity->toArray(); + } + return $entity; + }, $this->entities) : null, + 'animation' => ($this->animation instanceof ObjectTypeInterface) ? $this->animation->toArray() : null, + 'audio' => ($this->audio instanceof ObjectTypeInterface) ? $this->audio->toArray() : null, + 'document' => ($this->document instanceof ObjectTypeInterface) ? $this->document->toArray() : null, + 'photo' => is_array($this->photo) ? array_map(function ($photo) { + if ($photo instanceof ObjectTypeInterface) + { + return $photo->toArray(); + } + return $photo; + }, $this->photo) : null, + 'sticker' => ($this->sticker instanceof ObjectTypeInterface) ? $this->sticker->toArray() : null, + 'video' => ($this->video instanceof ObjectTypeInterface) ? $this->video->toArray() : null, + 'video_note' => ($this->video_note instanceof ObjectTypeInterface) ? $this->video_note->toArray() : null, + 'voice' => ($this->voice instanceof ObjectTypeInterface) ? $this->voice->toArray() : null, 'caption' => $this->caption, - 'caption_entities' => $caption_entities, + 'caption_entities' => is_array($this->caption_entities) ? array_map(function ($caption_entity) { + if ($caption_entity instanceof ObjectTypeInterface) + { + return $caption_entity->toArray(); + } + return $caption_entity; + }, $this->caption_entities) : null, 'has_media_spoiler' => $this->has_media_spoiler, - 'contact' => ($this->contact instanceof Contact) ? $this->contact->toArray() : null, - 'dice' => ($this->dice instanceof Dice) ? $this->dice->toArray() : null, - 'game' => ($this->game instanceof Game) ? $this->game->toArray() : null, - 'poll' => ($this->poll instanceof Poll) ? $this->poll->toArray() : null, - 'venue' => ($this->venue instanceof Venue) ? $this->venue->toArray() : null, - 'location' => ($this->location instanceof Location) ? $this->location->toArray() : null, - 'new_chat_members' => $new_chat_members, - 'left_chat_member' => ($this->left_chat_member instanceof User) ? $this->left_chat_member->toArray() : null, + 'contact' => ($this->contact instanceof ObjectTypeInterface) ? $this->contact->toArray() : null, + 'dice' => ($this->dice instanceof ObjectTypeInterface) ? $this->dice->toArray() : null, + 'game' => ($this->game instanceof ObjectTypeInterface) ? $this->game->toArray() : null, + 'poll' => ($this->poll instanceof ObjectTypeInterface) ? $this->poll->toArray() : null, + 'venue' => ($this->venue instanceof ObjectTypeInterface) ? $this->venue->toArray() : null, + 'location' => ($this->location instanceof ObjectTypeInterface) ? $this->location->toArray() : null, + 'new_chat_members' => is_array($this->new_chat_members) ? array_map(function ($new_chat_member) { + if ($new_chat_member instanceof ObjectTypeInterface) + { + return $new_chat_member->toArray(); + } + return $new_chat_member; + }, $this->new_chat_members) : null, + 'left_chat_member' => ($this->left_chat_member instanceof ObjectTypeInterface) ? $this->left_chat_member->toArray() : null, 'new_chat_title' => $this->new_chat_title, - 'new_chat_photo' => $new_chat_photo, + 'new_chat_photo' => is_array($this->new_chat_photo) ? array_map(function ($new_chat_photo) { + if ($new_chat_photo instanceof ObjectTypeInterface) + { + return $new_chat_photo->toArray(); + } + return $new_chat_photo; + }, $this->new_chat_photo) : null, 'delete_chat_photo' => $this->delete_chat_photo, 'group_chat_created' => $this->group_chat_created, 'supergroup_chat_created' => $this->supergroup_chat_created, 'channel_chat_created' => $this->channel_chat_created, - 'message_auto_delete_timer_changed' => ($this->message_auto_delete_timer_changed instanceof MessageAutoDeleteTimerChanged) ? $this->message_auto_delete_timer_changed->toArray() : null, + 'message_auto_delete_timer_changed' => ($this->message_auto_delete_timer_changed instanceof ObjectTypeInterface) ? $this->message_auto_delete_timer_changed->toArray() : null, 'migrate_to_chat_id' => $this->migrate_to_chat_id, - 'pinned_message' => ($this->pinned_message instanceof Message) ? $this->pinned_message->toArray() : null, - 'invoice' => ($this->invoice instanceof Invoice) ? $this->invoice->toArray() : null, - 'successful_payment' => ($this->successful_payment instanceof SuccessfulPayment) ? $this->successful_payment->toArray() : null, - 'user_shared' => ($this->user_shared instanceof UserShared) ? $this->user_shared->toArray() : null, - 'chat_shared' => ($this->chat_shared instanceof ChatShared) ? $this->chat_shared->toArray() : null, + 'pinned_message' => ($this->pinned_message instanceof ObjectTypeInterface) ? $this->pinned_message->toArray() : null, + 'invoice' => ($this->invoice instanceof ObjectTypeInterface) ? $this->invoice->toArray() : null, + 'successful_payment' => ($this->successful_payment instanceof ObjectTypeInterface) ? $this->successful_payment->toArray() : null, + 'user_shared' => ($this->user_shared instanceof ObjectTypeInterface) ? $this->user_shared->toArray() : null, + 'chat_shared' => ($this->chat_shared instanceof ObjectTypeInterface) ? $this->chat_shared->toArray() : null, 'connected_website' => $this->connected_website, - 'write_access_allowed' => ($this->write_access_allowed instanceof WriteAccessAllowed) ? $this->write_access_allowed->toArray() : null, - 'passport_data' => ($this->passport_data instanceof PassportData) ? $this->passport_data->toArray() : null, - 'proximity_alert_triggered' => ($this->proximity_alert_triggered instanceof ProximityAlertTriggered) ? $this->proximity_alert_triggered->toArray() : null, - 'forum_topic_created' => ($this->forum_topic_created instanceof ForumTopicCreated) ? $this->forum_topic_created->toArray() : null, - 'forum_topic_edited' => ($this->forum_topic_edited instanceof ForumTopicEdited) ? $this->forum_topic_edited->toArray() : null, - 'forum_topic_closed' => ($this->forum_topic_closed instanceof ForumTopicClosed) ? $this->forum_topic_closed->toArray() : null, - 'forum_topic_reopened' => ($this->forum_topic_reopened instanceof ForumTopicReopened) ? $this->forum_topic_reopened->toArray() : null, - 'general_forum_topic_hidden' => ($this->general_forum_topic_hidden instanceof GeneralForumTopicHidden) ? $this->general_forum_topic_hidden->toArray() : null, - 'general_forum_topic_unhidden' => ($this->general_forum_topic_unhidden instanceof GeneralForumTopicUnhidden) ? $this->general_forum_topic_unhidden->toArray() : null, - 'video_chat_scheduled' => ($this->video_chat_scheduled instanceof VideoChatScheduled) ? $this->video_chat_scheduled->toArray() : null, - 'video_chat_started' => ($this->video_chat_started instanceof VideoChatStarted) ? $this->video_chat_started->toArray() : null, - 'video_chat_ended' => ($this->video_chat_ended instanceof VideoChatEnded) ? $this->video_chat_ended->toArray() : null, - 'video_chat_participants_invited' => ($this->video_chat_participants_invited instanceof VideoChatParticipantsInvited) ? $this->video_chat_participants_invited->toArray() : null, - 'web_app_data' => ($this->web_app_data instanceof WebAppData) ? $this->web_app_data->toArray() : null, - 'reply_markup' => ($this->reply_markup instanceof InlineKeyboardMarkup) ? $this->reply_markup->toArray() : null, + 'write_access_allowed' => ($this->write_access_allowed instanceof ObjectTypeInterface) ? $this->write_access_allowed->toArray() : null, + 'passport_data' => ($this->passport_data instanceof ObjectTypeInterface) ? $this->passport_data->toArray() : null, + 'proximity_alert_triggered' => ($this->proximity_alert_triggered instanceof ObjectTypeInterface) ? $this->proximity_alert_triggered->toArray() : null, + 'forum_topic_created' => ($this->forum_topic_created instanceof ObjectTypeInterface) ? $this->forum_topic_created->toArray() : null, + 'forum_topic_edited' => ($this->forum_topic_edited instanceof ObjectTypeInterface) ? $this->forum_topic_edited->toArray() : null, + 'forum_topic_closed' => ($this->forum_topic_closed instanceof ObjectTypeInterface) ? $this->forum_topic_closed->toArray() : null, + 'forum_topic_reopened' => ($this->forum_topic_reopened instanceof ObjectTypeInterface) ? $this->forum_topic_reopened->toArray() : null, + 'general_forum_topic_hidden' => ($this->general_forum_topic_hidden instanceof ObjectTypeInterface) ? $this->general_forum_topic_hidden->toArray() : null, + 'general_forum_topic_unhidden' => ($this->general_forum_topic_unhidden instanceof ObjectTypeInterface) ? $this->general_forum_topic_unhidden->toArray() : null, + 'video_chat_scheduled' => ($this->video_chat_scheduled instanceof ObjectTypeInterface) ? $this->video_chat_scheduled->toArray() : null, + 'video_chat_started' => ($this->video_chat_started instanceof ObjectTypeInterface) ? $this->video_chat_started->toArray() : null, + 'video_chat_ended' => ($this->video_chat_ended instanceof ObjectTypeInterface) ? $this->video_chat_ended->toArray() : null, + 'video_chat_participants_invited' => ($this->video_chat_participants_invited instanceof ObjectTypeInterface) ? $this->video_chat_participants_invited->toArray() : null, + 'web_app_data' => ($this->web_app_data instanceof ObjectTypeInterface) ? $this->web_app_data->toArray() : null, + 'reply_markup' => ($this->reply_markup instanceof ObjectTypeInterface) ? $this->reply_markup->toArray() : null, ]; } @@ -1245,120 +1227,88 @@ { $object = new self(); - $object->message_id = @$data['message_id'] ?? null; - $object->message_thread_id = @$data['message_thread_id'] ?? null; - $object->from = (@$data['from'] !== null) ? User::fromArray($data['from']) : null; - $object->sender_chat = (@$data['sender_chat'] !== null) ? Chat::fromArray($data['sender_chat']) : null; - $object->date = @$data['date'] ?? null; - $object->chat = (@$data['chat'] !== null) ? Chat::fromArray($data['chat']) : null; - $object->forward_from = (@$data['forward_from'] !== null) ? User::fromArray($data['forward_from']) : null; - $object->forward_from_chat = (@$data['forward_from_chat'] !== null) ? Chat::fromArray($data['forward_from_chat']) : null; - $object->forward_from_message_id = @$data['forward_from_message_id'] ?? null; - $object->forward_signature = @$data['forward_signature'] ?? null; - $object->forward_sender_name = @$data['forward_sender_name'] ?? null; - $object->forward_date = @$data['forward_date'] ?? null; - $object->is_topic_message = @$data['is_topic_message'] ?? null; - $object->is_automatic_forward = @$data['is_automatic_forward'] ?? null; - $object->reply_to_message = (@$data['reply_to_message'] !== null) ? self::fromArray($data['reply_to_message']) : null; - $object->via_bot = (@$data['via_bot'] !== null) ? User::fromArray($data['via_bot']) : null; - $object->edit_date = @$data['edit_date'] ?? null; - $object->has_protected_content = @$data['has_protected_content'] ?? null; - $object->media_group_id = @$data['media_group_id'] ?? null; - $object->author_signature = @$data['author_signature'] ?? null; - $object->text = @$data['text'] ?? null; - - if (isset($data['entities']) && is_array($data['entities'])) { - $object->entities = []; - foreach ($data['entities'] as $item) { - $object->entities[] = MessageEntity::fromArray($item); - } - } - - $object->animation = (@$data['animation'] !== null) ? Animation::fromArray($data['animation']) : null; - $object->audio = (@$data['audio'] !== null) ? Audio::fromArray($data['audio']) : null; - $object->document = (@$data['document'] !== null) ? Document::fromArray($data['document']) : null; - - if (isset($data['photo']) && is_array($data['photo'])) + $object->message_id = $data['message_id'] ?? null; + $object->message_thread_id = $data['message_thread_id'] ?? null; + $object->from = ($data['from'] !== null) ? User::fromArray($data['from']) : null; + $object->sender_chat = ($data['sender_chat'] !== null) ? Chat::fromArray($data['sender_chat']) : null; + $object->date = $data['date'] ?? null; + $object->chat = ($data['chat'] !== null) ? Chat::fromArray($data['chat']) : null; + $object->forward_from = ($data['forward_from'] !== null) ? User::fromArray($data['forward_from']) : null; + $object->forward_from_chat = ($data['forward_from_chat'] !== null) ? Chat::fromArray($data['forward_from_chat']) : null; + $object->forward_from_message_id = $data['forward_from_message_id'] ?? null; + $object->forward_signature = $data['forward_signature'] ?? null; + $object->forward_sender_name = $data['forward_sender_name'] ?? null; + $object->forward_date = $data['forward_date'] ?? null; + $object->is_topic_message = $data['is_topic_message'] ?? null; + $object->is_automatic_forward = $data['is_automatic_forward'] ?? null; + $object->reply_to_message = ($data['reply_to_message'] !== null) ? self::fromArray($data['reply_to_message']) : null; + $object->via_bot = ($data['via_bot'] !== null) ? User::fromArray($data['via_bot']) : null; + $object->edit_date = $data['edit_date'] ?? null; + $object->has_protected_content = $data['has_protected_content'] ?? null; + $object->media_group_id = $data['media_group_id'] ?? null; + $object->author_signature = $data['author_signature'] ?? null; + $object->text = $data['text'] ?? null; + $object->entities = isset($data['entities']) && is_array($data['entities']) ? array_map(function ($item) { + return MessageEntity::fromArray($item); + }, $data['entities']) : null; + $object->animation = ($data['animation'] !== null) ? Animation::fromArray($data['animation']) : null; + $object->audio = ($data['audio'] !== null) ? Audio::fromArray($data['audio']) : null; + $object->document = ($data['document'] !== null) ? Document::fromArray($data['document']) : null; + $object->photo = isset($data['photo']) && is_array($data['photo']) ? array_map(function ($item) { - $object->photo = []; - foreach ($data['photo'] as $item) - { - $object->photo[] = PhotoSize::fromArray($item); - } - } - - $object->sticker = (@$data['sticker'] !== null) ? Sticker::fromArray($data['sticker']) : null; - $object->video = (@$data['video'] !== null) ? Video::fromArray($data['video']) : null; - $object->video_note = (@$data['video_note'] !== null) ? VideoNote::fromArray($data['video_note']) : null; - $object->voice = (@$data['voice'] !== null) ? Voice::fromArray($data['voice']) : null; - $object->caption = @$data['caption'] ?? null; - - if (isset($data['caption_entities']) && is_array($data['caption_entities'])) - { - $object->caption_entities = []; - foreach ($data['caption_entities'] as $item) - { - $object->caption_entities[] = MessageEntity::fromArray($item); - } - } - - $object->has_media_spoiler = @$data['has_media_spoiler'] ?? null; - $object->contact = (@$data['contact'] !== null) ? Contact::fromArray($data['contact']) : null; - $object->dice = (@$data['dice'] !== null) ? Dice::fromArray($data['dice']) : null; - $object->game = (@$data['game'] !== null) ? Game::fromArray($data['game']) : null; - $object->poll = (@$data['poll'] !== null) ? Poll::fromArray($data['poll']) : null; - $object->venue = (@$data['venue'] !== null) ? Venue::fromArray($data['venue']) : null; - $object->location = (@$data['location'] !== null) ? Location::fromArray($data['location']) : null; - - if (isset($data['new_chat_members']) && is_array($data['new_chat_members'])) - { - $object->new_chat_members = []; - foreach ($data['new_chat_members'] as $item) - { - $object->new_chat_members[] = User::fromArray($item); - } - } - - $object->left_chat_member = (@$data['left_chat_member'] !== null) ? User::fromArray($data['left_chat_member']) : null; - $object->new_chat_title = @$data['new_chat_title'] ?? null; - - if (isset($data['new_chat_photo']) && is_array($data['new_chat_photo'])) - { - $object->new_chat_photo = []; - foreach ($data['new_chat_photo'] as $item) - { - $object->new_chat_photo[] = PhotoSize::fromArray($item); - } - } - - $object->delete_chat_photo = @$data['delete_chat_photo'] ?? null; - $object->group_chat_created = @$data['group_chat_created'] ?? null; - $object->supergroup_chat_created = @$data['supergroup_chat_created'] ?? null; - $object->channel_chat_created = @$data['channel_chat_created'] ?? null; - $object->message_auto_delete_timer_changed = (@$data['message_auto_delete_timer_changed'] !== null) ? MessageAutoDeleteTimerChanged::fromArray($data['message_auto_delete_timer_changed']) : null; - $object->migrate_to_chat_id = @$data['migrate_to_chat_id'] ?? null; - $object->migrate_from_chat_id = @$data['migrate_from_chat_id'] ?? null; - $object->pinned_message = (@$data['pinned_message'] !== null) ? self::fromArray($data['pinned_message']) : null; - $object->invoice = (@$data['invoice'] !== null) ? Invoice::fromArray($data['invoice']) : null; - $object->successful_payment = (@$data['successful_payment'] !== null) ? SuccessfulPayment::fromArray($data['successful_payment']) : null; - $object->user_shared = (@$data['user_shared'] !== null) ? UserShared::fromArray($data['user_shared']) : null; - $object->chat_shared = (@$data['chat_shared'] !== null) ? ChatShared::fromArray($data['chat_shared']) : null; - $object->connected_website = @$data['connected_website'] ?? null; - $object->write_access_allowed = (@$data['write_access_allowed'] !== null) ? WriteAccessAllowed::fromArray($data['write_access_allowed']) : null; - $object->passport_data = (@$data['passport_data'] !== null) ? PassportData::fromArray($data['passport_data']) : null; - $object->proximity_alert_triggered = (@$data['proximity_alert_triggered'] !== null) ? ProximityAlertTriggered::fromArray($data['proximity_alert_triggered']) : null; - $object->forum_topic_created = (@$data['forum_topic_created'] !== null) ? ForumTopicCreated::fromArray($data['forum_topic_created']) : null; - $object->forum_topic_edited = (@$data['forum_topic_edited'] !== null) ? ForumTopicEdited::fromArray($data['forum_topic_edited']) : null; - $object->forum_topic_closed = (@$data['forum_topic_closed'] !== null) ? ForumTopicClosed::fromArray($data['forum_topic_closed']) : null; - $object->forum_topic_reopened = (@$data['forum_topic_reopened'] !== null) ? ForumTopicReopened::fromArray($data['forum_topic_reopened']) : null; - $object->general_forum_topic_hidden = (@$data['general_forum_topic_hidden'] !== null) ? GeneralForumTopicHidden::fromArray($data['general_forum_topic_hidden']) : null; - $object->general_forum_topic_unhidden = (@$data['general_forum_topic_unhidden'] !== null) ? GeneralForumTopicUnhidden::fromArray($data['general_forum_topic_unhidden']) : null; - $object->video_chat_scheduled = (@$data['video_chat_scheduled'] !== null) ? VideoChatScheduled::fromArray($data['video_chat_scheduled']) : null; - $object->video_chat_started = (@$data['video_chat_started'] !== null) ? VideoChatStarted::fromArray($data['video_chat_started']) : null; - $object->video_chat_ended = (@$data['video_chat_ended'] !== null) ? VideoChatEnded::fromArray($data['video_chat_ended']) : null; - $object->video_chat_participants_invited = (@$data['video_chat_participants_invited'] !== null) ? VideoChatParticipantsInvited::fromArray($data['video_chat_participants_invited']) : null; - $object->web_app_data = (@$data['web_app_data'] !== null) ? WebAppData::fromArray($data['web_app_data']) : null; - $object->reply_markup = (@$data['reply_markup'] !== null) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null; + return PhotoSize::fromArray($item); + }, $data['photo']) : null; + $object->sticker = ($data['sticker'] !== null) ? Sticker::fromArray($data['sticker']) : null; + $object->video = ($data['video'] !== null) ? Video::fromArray($data['video']) : null; + $object->video_note = ($data['video_note'] !== null) ? VideoNote::fromArray($data['video_note']) : null; + $object->voice = ($data['voice'] !== null) ? Voice::fromArray($data['voice']) : null; + $object->caption = $data['caption'] ?? null; + $object->caption_entities = isset($data['caption_entities']) && is_array($data['caption_entities']) ? array_map(function ($item) { + return MessageEntity::fromArray($item); + }, $data['caption_entities']) : null; + $object->has_media_spoiler = $data['has_media_spoiler'] ?? null; + $object->contact = ($data['contact'] !== null) ? Contact::fromArray($data['contact']) : null; + $object->dice = ($data['dice'] !== null) ? Dice::fromArray($data['dice']) : null; + $object->game = ($data['game'] !== null) ? Game::fromArray($data['game']) : null; + $object->poll = ($data['poll'] !== null) ? Poll::fromArray($data['poll']) : null; + $object->venue = ($data['venue'] !== null) ? Venue::fromArray($data['venue']) : null; + $object->location = ($data['location'] !== null) ? Location::fromArray($data['location']) : null; + $object->new_chat_members = isset($data['new_chat_members']) && is_array($data['new_chat_members']) ? array_map(function ($item) { + return User::fromArray($item); + }, $data['new_chat_members']) : null; + $object->left_chat_member = ($data['left_chat_member'] !== null) ? User::fromArray($data['left_chat_member']) : null; + $object->new_chat_title = $data['new_chat_title'] ?? null; + $object->new_chat_photo = isset($data['new_chat_photo']) && is_array($data['new_chat_photo']) ? array_map(function ($item) { + return PhotoSize::fromArray($item); + }, $data['new_chat_photo']) : null; + $object->delete_chat_photo = $data['delete_chat_photo'] ?? null; + $object->group_chat_created = $data['group_chat_created'] ?? null; + $object->supergroup_chat_created = $data['supergroup_chat_created'] ?? null; + $object->channel_chat_created = $data['channel_chat_created'] ?? null; + $object->message_auto_delete_timer_changed = ($data['message_auto_delete_timer_changed'] !== null) ? MessageAutoDeleteTimerChanged::fromArray($data['message_auto_delete_timer_changed']) : null; + $object->migrate_to_chat_id = $data['migrate_to_chat_id'] ?? null; + $object->migrate_from_chat_id = $data['migrate_from_chat_id'] ?? null; + $object->pinned_message = ($data['pinned_message'] !== null) ? self::fromArray($data['pinned_message']) : null; + $object->invoice = ($data['invoice'] !== null) ? Invoice::fromArray($data['invoice']) : null; + $object->successful_payment = ($data['successful_payment'] !== null) ? SuccessfulPayment::fromArray($data['successful_payment']) : null; + $object->user_shared = ($data['user_shared'] !== null) ? UserShared::fromArray($data['user_shared']) : null; + $object->chat_shared = ($data['chat_shared'] !== null) ? ChatShared::fromArray($data['chat_shared']) : null; + $object->connected_website = $data['connected_website'] ?? null; + $object->write_access_allowed = ($data['write_access_allowed'] !== null) ? WriteAccessAllowed::fromArray($data['write_access_allowed']) : null; + $object->passport_data = ($data['passport_data'] !== null) ? PassportData::fromArray($data['passport_data']) : null; + $object->proximity_alert_triggered = ($data['proximity_alert_triggered'] !== null) ? ProximityAlertTriggered::fromArray($data['proximity_alert_triggered']) : null; + $object->forum_topic_created = ($data['forum_topic_created'] !== null) ? ForumTopicCreated::fromArray($data['forum_topic_created']) : null; + $object->forum_topic_edited = ($data['forum_topic_edited'] !== null) ? ForumTopicEdited::fromArray($data['forum_topic_edited']) : null; + $object->forum_topic_closed = ($data['forum_topic_closed'] !== null) ? ForumTopicClosed::fromArray($data['forum_topic_closed']) : null; + $object->forum_topic_reopened = ($data['forum_topic_reopened'] !== null) ? ForumTopicReopened::fromArray($data['forum_topic_reopened']) : null; + $object->general_forum_topic_hidden = ($data['general_forum_topic_hidden'] !== null) ? GeneralForumTopicHidden::fromArray($data['general_forum_topic_hidden']) : null; + $object->general_forum_topic_unhidden = ($data['general_forum_topic_unhidden'] !== null) ? GeneralForumTopicUnhidden::fromArray($data['general_forum_topic_unhidden']) : null; + $object->video_chat_scheduled = ($data['video_chat_scheduled'] !== null) ? VideoChatScheduled::fromArray($data['video_chat_scheduled']) : null; + $object->video_chat_started = ($data['video_chat_started'] !== null) ? VideoChatStarted::fromArray($data['video_chat_started']) : null; + $object->video_chat_ended = ($data['video_chat_ended'] !== null) ? VideoChatEnded::fromArray($data['video_chat_ended']) : null; + $object->video_chat_participants_invited = ($data['video_chat_participants_invited'] !== null) ? VideoChatParticipantsInvited::fromArray($data['video_chat_participants_invited']) : null; + $object->web_app_data = ($data['web_app_data'] !== null) ? WebAppData::fromArray($data['web_app_data']) : null; + $object->reply_markup = ($data['reply_markup'] !== null) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null; return $object; } diff --git a/src/TgBotLib/Objects/MessageAutoDeleteTimerChanged.php b/src/TgBotLib/Objects/MessageAutoDeleteTimerChanged.php index f0412a9..98a8f98 100644 --- a/src/TgBotLib/Objects/MessageAutoDeleteTimerChanged.php +++ b/src/TgBotLib/Objects/MessageAutoDeleteTimerChanged.php @@ -42,6 +42,7 @@ public static function fromArray(array $data): ObjectTypeInterface { $object = new self(); + $object->message_auto_delete_time = $data['message_auto_delete_time']; return $object; diff --git a/src/TgBotLib/Objects/MessageEntity.php b/src/TgBotLib/Objects/MessageEntity.php index 9b23003..c035092 100644 --- a/src/TgBotLib/Objects/MessageEntity.php +++ b/src/TgBotLib/Objects/MessageEntity.php @@ -128,13 +128,13 @@ public function toArray(): array { return [ - 'type' => $this->type ?? null, - 'offset' => $this->offset ?? null, - 'length' => $this->length ?? null, - 'url' => $this->url ?? null, - 'user' => ($this->user instanceof User) ? $this->user->toArray() : null, - 'language' => $this->language ?? null, - 'custom_emoji_id' => $this->custom_emoji_id ?? null, + 'type' => $this->type, + 'offset' => $this->offset, + 'length' => $this->length, + 'url' => $this->url, + 'user' => ($this->user instanceof ObjectTypeInterface) ? $this->user->toArray() : null, + 'language' => $this->language, + 'custom_emoji_id' => $this->custom_emoji_id ]; } diff --git a/src/TgBotLib/Objects/PassportData.php b/src/TgBotLib/Objects/PassportData.php index 9928f43..31ee1fb 100644 --- a/src/TgBotLib/Objects/PassportData.php +++ b/src/TgBotLib/Objects/PassportData.php @@ -46,9 +46,13 @@ public function toArray(): array { return [ - 'data' => array_map(function (EncryptedPassportElement $element) + 'data' => array_map(function ($element) { - return $element->toArray(); + if($element instanceof ObjectTypeInterface) + { + return $element->toArray(); + } + return $element; }, $this->data), 'credentials' => $this->credentials->toArray(), ]; diff --git a/src/TgBotLib/Objects/PassportFile.php b/src/TgBotLib/Objects/PassportFile.php index d976130..89c3c2f 100644 --- a/src/TgBotLib/Objects/PassportFile.php +++ b/src/TgBotLib/Objects/PassportFile.php @@ -94,10 +94,10 @@ { $object = new self(); - $object->file_id = $data['file_id']; - $object->file_unique_id = $data['file_unique_id']; - $object->file_size = $data['file_size']; - $object->file_date = $data['file_date']; + $object->file_id = $data['file_id'] ?? null; + $object->file_unique_id = $data['file_unique_id'] ?? null; + $object->file_size = $data['file_size'] ?? null; + $object->file_date = $data['file_date'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/PhotoSize.php b/src/TgBotLib/Objects/PhotoSize.php index 05a8857..777d097 100644 --- a/src/TgBotLib/Objects/PhotoSize.php +++ b/src/TgBotLib/Objects/PhotoSize.php @@ -1,5 +1,7 @@ file_id = $data['file_id']; - $object->file_unique_id = $data['file_unique_id']; - $object->width = $data['width']; - $object->height = $data['height']; + $object->file_id = $data['file_id'] ?? null; + $object->file_unique_id = $data['file_unique_id'] ?? null; + $object->width = $data['width'] ?? null; + $object->height = $data['height'] ?? null; $object->file_size = $data['file_size'] ?? null; return $object; diff --git a/src/TgBotLib/Objects/PollAnswer.php b/src/TgBotLib/Objects/PollAnswer.php index 2ee79db..9993958 100644 --- a/src/TgBotLib/Objects/PollAnswer.php +++ b/src/TgBotLib/Objects/PollAnswer.php @@ -62,7 +62,7 @@ { return [ 'poll_id' => $this->poll_id, - 'user' => $this->user->toArray(), + 'user' => ($this->user instanceof ObjectTypeInterface) ? $this->user->toArray() : null, 'option_ids' => $this->option_ids, ]; } @@ -77,8 +77,8 @@ { $object = new self(); - $object->poll_id = $data['poll_id']; - $object->user = User::fromArray($data['user']); + $object->poll_id = $data['poll_id'] ?? null; + $object->user = isset($data['user']) && is_array($data['user']) ? User::fromArray($data['user']) : null; $object->option_ids = $data['option_ids']; return $object; diff --git a/src/TgBotLib/Objects/PollOption.php b/src/TgBotLib/Objects/PollOption.php index abf5cc4..fbdfa53 100644 --- a/src/TgBotLib/Objects/PollOption.php +++ b/src/TgBotLib/Objects/PollOption.php @@ -61,8 +61,8 @@ { $object = new self(); - $object->text = $data['text']; - $object->voter_count = $data['voter_count']; + $object->text = $data['text'] ?? null; + $object->voter_count = $data['voter_count'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/PreCheckoutQuery.php b/src/TgBotLib/Objects/PreCheckoutQuery.php index ce12384..2d6076d 100644 --- a/src/TgBotLib/Objects/PreCheckoutQuery.php +++ b/src/TgBotLib/Objects/PreCheckoutQuery.php @@ -125,12 +125,12 @@ { return [ 'id' => $this->id, - 'from' => ($this->from instanceof User) ? $this->from->toArray() : null, + 'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : null, 'currency' => $this->currency, 'total_amount' => $this->total_amount, 'invoice_payload' => $this->invoice_payload, 'shipping_option_id' => $this->shipping_option_id, - 'order_info' => ($this->order_info instanceof OrderInfo) ? $this->order_info->toArray() : null + 'order_info' => ($this->order_info instanceof ObjectTypeInterface) ? $this->order_info->toArray() : null ]; } @@ -143,13 +143,13 @@ public static function fromArray(array $data): ObjectTypeInterface { $object = new self(); - $object->id = $data['id']; - $object->from = User::fromArray($data['from']); - $object->currency = $data['currency']; - $object->total_amount = $data['total_amount']; - $object->invoice_payload = $data['invoice_payload']; + $object->id = $data['id'] ?? null; + $object->from = isset($data['from']) && is_array($data['from']) ? User::fromArray($data['from']) : null; + $object->currency = $data['currency'] ?? null; + $object->total_amount = $data['total_amount'] ?? null; + $object->invoice_payload = $data['invoice_payload'] ?? null; $object->shipping_option_id = $data['shipping_option_id'] ?? null; - $object->order_info = OrderInfo::fromArray($data['order_info']) ?? null; + $object->order_info = isset($data['order_info']) && is_array($data['order_info']) ? OrderInfo::fromArray($data['order_info']) : null; return $object; } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/ProximityAlertTriggered.php b/src/TgBotLib/Objects/ProximityAlertTriggered.php index 29c165a..19814a3 100644 --- a/src/TgBotLib/Objects/ProximityAlertTriggered.php +++ b/src/TgBotLib/Objects/ProximityAlertTriggered.php @@ -1,5 +1,7 @@ traveler = User::fromArray($data['traveler']); - $object->watcher = User::fromArray($data['watcher']); + $object->traveler = isset($data['traveler']) && is_array($data['traveler']) ? User::fromArray($data['traveler']) : $data['traveler']; + $object->watcher = isset($data['watcher']) && is_array($data['watcher']) ? User::fromArray($data['watcher']) : $data['watcher']; $object->distance = $data['distance']; return $object; diff --git a/src/TgBotLib/Objects/ReplyKeyboardMarkup.php b/src/TgBotLib/Objects/ReplyKeyboardMarkup.php index a161a82..eaaffbc 100644 --- a/src/TgBotLib/Objects/ReplyKeyboardMarkup.php +++ b/src/TgBotLib/Objects/ReplyKeyboardMarkup.php @@ -1,5 +1,7 @@ keyboard = $data['keyboard']; - $object->is_persistent = $data['is_persistent']; - $object->resize_keyboard = $data['resize_keyboard']; - $object->one_time_keyboard = $data['one_time_keyboard']; - $object->input_field_placeholder = $data['input_field_placeholder']; - $object->selective = $data['selective']; + $object->keyboard = $data['keyboard'] ?? null; + $object->is_persistent = $data['is_persistent'] ?? null; + $object->resize_keyboard = $data['resize_keyboard'] ?? null; + $object->one_time_keyboard = $data['one_time_keyboard'] ?? null; + $object->input_field_placeholder = $data['input_field_placeholder'] ?? null; + $object->selective = $data['selective'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/ReplyKeyboardRemove.php b/src/TgBotLib/Objects/ReplyKeyboardRemove.php index 5fe6921..1975643 100644 --- a/src/TgBotLib/Objects/ReplyKeyboardRemove.php +++ b/src/TgBotLib/Objects/ReplyKeyboardRemove.php @@ -66,8 +66,8 @@ public static function fromArray(array $data): ObjectTypeInterface { $object = new self(); - $object->remove_keyboard = @$data['remove_keyboard'] ?? false; - $object->selective = @$data['selective'] ?? false; + $object->remove_keyboard = $data['remove_keyboard'] ?? false; + $object->selective = $data['selective'] ?? false; return $object; } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/ShippingQuery.php b/src/TgBotLib/Objects/ShippingQuery.php index b47513e..a08e1be 100644 --- a/src/TgBotLib/Objects/ShippingQuery.php +++ b/src/TgBotLib/Objects/ShippingQuery.php @@ -93,10 +93,10 @@ { $object = new self(); - $object->id = $data['id']; - $object->from = User::fromArray($data['from']); - $object->invoice_payload = $data['invoice_payload']; - $object->shipping_address = ShippingAddress::fromArray($data['shipping_address']); + $object->id = $data['id'] ?? null; + $object->from = isset($data['from']) && is_array($data['from']) ? User::fromArray($data['from']) : $data['from']; + $object->invoice_payload = $data['invoice_payload'] ?? null; + $object->shipping_address = isset($data['shipping_address']) && is_array($data['shipping_address']) ? ShippingAddress::fromArray($data['shipping_address']) : $data['shipping_address']; return $object; } diff --git a/src/TgBotLib/Objects/Sticker.php b/src/TgBotLib/Objects/Sticker.php index a0841f8..186b958 100644 --- a/src/TgBotLib/Objects/Sticker.php +++ b/src/TgBotLib/Objects/Sticker.php @@ -237,11 +237,11 @@ 'height' => $this->height, 'is_animated' => $this->is_animated, 'is_video' => $this->is_video, - 'thumb' => ($this->thumb instanceof PhotoSize) ? $this->thumb->toArray() : null, + 'thumb' => ($this->thumb instanceof ObjectTypeInterface) ? $this->thumb->toArray() : $this->thumb, 'emoji' => $this->emoji, 'set_name' => $this->set_name, - 'premium_animation' => ($this->premium_animation instanceof File) ? $this->premium_animation->toArray() : null, - 'mask_position' => ($this->mask_position instanceof MaskPosition) ? $this->mask_position->toArray() : null, + 'premium_animation' => ($this->premium_animation instanceof ObjectTypeInterface) ? $this->premium_animation->toArray() : $this->thumb, + 'mask_position' => ($this->mask_position instanceof ObjectTypeInterface) ? $this->mask_position->toArray() : $this->mask_position, 'custom_emoji_id' => $this->custom_emoji_id, 'file_size' => $this->file_size, ]; diff --git a/src/TgBotLib/Objects/SuccessfulPayment.php b/src/TgBotLib/Objects/SuccessfulPayment.php index b5dbb20..a48c26c 100644 --- a/src/TgBotLib/Objects/SuccessfulPayment.php +++ b/src/TgBotLib/Objects/SuccessfulPayment.php @@ -129,7 +129,7 @@ 'total_amount' => $this->total_amount, 'invoice_payload' => $this->invoice_payload, 'shipping_option_id' => $this->shipping_option_id, - 'order_info' => ($this->order_info instanceof OrderInfo) ? $this->order_info->toArray() : null, + 'order_info' => ($this->order_info instanceof ObjectTypeInterface) ? $this->order_info->toArray() : null, 'telegram_payment_charge_id' => $this->telegram_payment_charge_id, 'provider_payment_charge_id' => $this->provider_payment_charge_id, ]; @@ -145,13 +145,13 @@ { $object = new self(); - $object->currency = $data['currency']; - $object->total_amount = $data['total_amount']; - $object->invoice_payload = $data['invoice_payload']; + $object->currency = $data['currency'] ?? null; + $object->total_amount = $data['total_amount'] ?? null; + $object->invoice_payload = $data['invoice_payload'] ?? null; $object->shipping_option_id = $data['shipping_option_id'] ?? null; $object->order_info = isset($data['order_info']) ? OrderInfo::fromArray($data['order_info']) : null; - $object->telegram_payment_charge_id = $data['telegram_payment_charge_id']; - $object->provider_payment_charge_id = $data['provider_payment_charge_id']; + $object->telegram_payment_charge_id = $data['telegram_payment_charge_id'] ?? null; + $object->provider_payment_charge_id = $data['provider_payment_charge_id'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/User.php b/src/TgBotLib/Objects/User.php index a2fe080..6fa2f6e 100644 --- a/src/TgBotLib/Objects/User.php +++ b/src/TgBotLib/Objects/User.php @@ -80,7 +80,7 @@ * * @return bool */ - public function isIsBot(): bool + public function isBot(): bool { return $this->is_bot; } @@ -131,7 +131,7 @@ * * @return bool */ - public function isIsPremium(): bool + public function isPremium(): bool { return $this->is_premium; } @@ -152,7 +152,7 @@ * @see https://core.telegram.org/bots/api#getme * @return bool */ - public function isCanJoinGroups(): bool + public function canJoinGroups(): bool { return $this->can_join_groups; } @@ -164,7 +164,7 @@ * @see https://core.telegram.org/bots#privacy-mode * @return bool */ - public function isCanReadAllGroupMessages(): bool + public function canReadAllGroupMessages(): bool { return $this->can_read_all_group_messages; } @@ -174,7 +174,7 @@ * * @return bool */ - public function isSupportsInlineQueries(): bool + public function supportsInlineQueries(): bool { return $this->supports_inline_queries; } @@ -211,17 +211,17 @@ { $object = new self(); - $object->id = @$data['id']; - $object->is_bot = @$data['is_bot']; - $object->first_name = @$data['first_name']; - $object->last_name = @$data['last_name'] ?? null; - $object->username = @$data['username'] ?? null; - $object->language_code = @$data['language_code'] ?? null; - $object->is_premium = @$data['is_premium'] ?? false; - $object->added_to_attachment_menu = @$data['added_to_attachment_menu'] ?? false; - $object->can_join_groups = @$data['can_join_groups'] ?? false; - $object->can_read_all_group_messages = @$data['can_read_all_group_messages'] ?? false; - $object->supports_inline_queries = @$data['supports_inline_queries'] ?? false; + $object->id = $data['id'] ?? null; + $object->is_bot = $data['is_bot'] ?? false; + $object->first_name = $data['first_name'] ?? null; + $object->last_name = $data['last_name'] ?? null; + $object->username = $data['username'] ?? null; + $object->language_code = $data['language_code'] ?? null; + $object->is_premium = $data['is_premium'] ?? false; + $object->added_to_attachment_menu = $data['added_to_attachment_menu'] ?? false; + $object->can_join_groups = $data['can_join_groups'] ?? false; + $object->can_read_all_group_messages = $data['can_read_all_group_messages'] ?? false; + $object->supports_inline_queries = $data['supports_inline_queries'] ?? false; return $object; } diff --git a/src/TgBotLib/Objects/Venue.php b/src/TgBotLib/Objects/Venue.php index a66c9f5..d149bab 100644 --- a/src/TgBotLib/Objects/Venue.php +++ b/src/TgBotLib/Objects/Venue.php @@ -121,7 +121,7 @@ public function toArray(): array { return [ - 'location' => ($this->location instanceof Location) ? $this->location->toArray() : $this->location, + 'location' => ($this->location instanceof ObjectTypeInterface) ? $this->location->toArray() : $this->location, 'title' => $this->title, 'address' => $this->address, 'foursquare_id' => $this->foursquare_id, @@ -142,12 +142,12 @@ $object = new self(); $object->location = isset($data['location']) ? Location::fromArray($data['location']) : null; - $object->title = @$data['title']; - $object->address = @$data['address']; - $object->foursquare_id = @$data['foursquare_id'] ?? null; - $object->foursquare_type = @$data['foursquare_type'] ?? null; - $object->google_place_id = @$data['google_place_id'] ?? null; - $object->google_place_type = @$data['google_place_type'] ?? null; + $object->title = $data['title']; + $object->address = $data['address']; + $object->foursquare_id = $data['foursquare_id'] ?? null; + $object->foursquare_type = $data['foursquare_type'] ?? null; + $object->google_place_id = $data['google_place_id'] ?? null; + $object->google_place_type = $data['google_place_type'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/Video.php b/src/TgBotLib/Objects/Video.php index 10f4200..21c27c1 100644 --- a/src/TgBotLib/Objects/Video.php +++ b/src/TgBotLib/Objects/Video.php @@ -157,7 +157,7 @@ 'width' => $this->width, 'height' => $this->height, 'duration' => $this->duration, - 'thumb' => ($this->thumb instanceof PhotoSize) ? $this->thumb->toArray() : null, + 'thumb' => ($this->thumb instanceof ObjectTypeInterface) ? $this->thumb->toArray() : null, 'file_name' => $this->file_name ?? null, 'mime_type' => $this->mime_type ?? null, 'file_size' => $this->file_size ?? null, diff --git a/src/TgBotLib/Objects/VideoNote.php b/src/TgBotLib/Objects/VideoNote.php index 1c076c3..a022955 100644 --- a/src/TgBotLib/Objects/VideoNote.php +++ b/src/TgBotLib/Objects/VideoNote.php @@ -109,7 +109,7 @@ 'file_unique_id' => $this->file_unique_id, 'length' => $this->length, 'duration' => $this->duration, - 'thumb' => ($this->thumb instanceof PhotoSize) ? $this->thumb->toArray() : null, + 'thumb' => ($this->thumb instanceof ObjectTypeInterface) ? $this->thumb->toArray() : $this->thumb, 'file_size' => $this->file_size, ]; } @@ -124,12 +124,12 @@ { $object = new self(); - $object->file_id = @$data['file_id']; - $object->file_unique_id = @$data['file_unique_id']; - $object->length = @$data['length']; - $object->duration = @$data['duration']; + $object->file_id = $data['file_id']; + $object->file_unique_id = $data['file_unique_id']; + $object->length = $data['length']; + $object->duration = $data['duration']; $object->thumb = (isset($data['thumb'])) ? PhotoSize::fromArray($data['thumb']) : null; - $object->file_size = @$data['file_size']; + $object->file_size = $data['file_size']; return $object; } diff --git a/src/TgBotLib/Objects/Voice.php b/src/TgBotLib/Objects/Voice.php index e17dd7f..4eb6b43 100644 --- a/src/TgBotLib/Objects/Voice.php +++ b/src/TgBotLib/Objects/Voice.php @@ -111,11 +111,11 @@ { $object = new self(); - $object->file_id = @$data['file_id']; - $object->file_unique_id = @$data['file_unique_id']; - $object->duration = @$data['duration']; - $object->mime_type = @$data['mime_type'] ?? null; - $object->file_size = @$data['file_size'] ?? null; + $object->file_id = $data['file_id']; + $object->file_unique_id = $data['file_unique_id']; + $object->duration = $data['duration']; + $object->mime_type = $data['mime_type'] ?? null; + $object->file_size = $data['file_size'] ?? null; return $object; } diff --git a/src/TgBotLib/Objects/WebAppData.php b/src/TgBotLib/Objects/WebAppData.php index aea4dd1..198df7b 100644 --- a/src/TgBotLib/Objects/WebAppData.php +++ b/src/TgBotLib/Objects/WebAppData.php @@ -60,8 +60,8 @@ { $object = new self(); - $object->data = @$data['data'] ?: ''; - $object->button_text = @$data['button_text'] ?: ''; + $object->data = $data['data'] ?: ''; + $object->button_text = $data['button_text'] ?: ''; return $object; }