Major Refactoring

This commit is contained in:
Netkas 2023-02-14 17:35:16 -05:00
parent 3de87df2d9
commit 54a8a59ee8
83 changed files with 892 additions and 918 deletions

1
.idea/php.xml generated
View file

@ -9,6 +9,7 @@
<component name="PHPCodeSnifferOptionsConfiguration"> <component name="PHPCodeSnifferOptionsConfiguration">
<option name="transferred" value="true" /> <option name="transferred" value="true" />
</component> </component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.2" />
<component name="PhpStanOptionsConfiguration"> <component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" /> <option name="transferred" value="true" />
</component> </component>

4
.idea/tgbot.iml generated
View file

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>

View file

@ -159,7 +159,7 @@
'width' => $this->width ?? null, 'width' => $this->width ?? null,
'height' => $this->height ?? null, 'height' => $this->height ?? null,
'duration' => $this->duration ?? 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, 'file_name' => $this->file_name ?? null,
'mime_type' => $this->mime_type ?? null, 'mime_type' => $this->mime_type ?? null,
'file_size' => $this->file_size ?? null 'file_size' => $this->file_size ?? null

View file

@ -1,5 +1,7 @@
<?php <?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects; namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
@ -155,7 +157,7 @@
'file_name' => $this->file_name ?? null, 'file_name' => $this->file_name ?? null,
'mime_type' => $this->mime_type ?? null, 'mime_type' => $this->mime_type ?? null,
'file_size' => $this->file_size ?? 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,
]; ];
} }

View file

@ -61,8 +61,8 @@
{ {
$object = new self(); $object = new self();
$object->command = $data['command']; $object->command = $data['command'] ?? null;
$object->description = $data['description']; $object->description = $data['description'] ?? null;
return $object; return $object;
} }

View file

@ -5,6 +5,9 @@
namespace TgBotLib\Objects; namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\BotCommandScope\BotCommandScopeChat;
use TgBotLib\Objects\BotCommandScope\BotCommandScopeChatAdministrators;
use TgBotLib\Objects\BotCommandScope\BotCommandScopeChatMember;
class BotCommandScope implements ObjectTypeInterface class BotCommandScope implements ObjectTypeInterface
{ {
@ -76,9 +79,22 @@
*/ */
public static function fromArray(array $data): ObjectTypeInterface 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 = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? null;
$object->chat_id = $data['chat_id'] ?? null; $object->chat_id = $data['chat_id'] ?? null;
$object->user_id = $data['user_id'] ?? null; $object->user_id = $data['user_id'] ?? null;

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\BotCommandScope; namespace TgBotLib\Objects\BotCommandScope;
use TgBotLib\Abstracts\BotCommandScopeType;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\BotCommandScope; use TgBotLib\Objects\BotCommandScope;
@ -20,7 +21,7 @@
private $chat_id; private $chat_id;
/** /**
* Scope type, must be chat_administrators * Scope type, must be all_chat_administrators
* *
* @return string * @return string
*/ */
@ -61,8 +62,10 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $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; return $object;
} }
@ -75,8 +78,10 @@
public static function fromBotCommandScope(BotCommandScope $botCommandScope): self public static function fromBotCommandScope(BotCommandScope $botCommandScope): self
{ {
$object = new self(); $object = new self();
$object->type = $botCommandScope->getType(); $object->type = $botCommandScope->getType();
$object->chat_id = $botCommandScope->getChatId(); $object->chat_id = $botCommandScope->getChatId();
return $object; return $object;
} }
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\BotCommandScope; namespace TgBotLib\Objects\BotCommandScope;
use TgBotLib\Abstracts\BotCommandScopeType;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\BotCommandScope; use TgBotLib\Objects\BotCommandScope;
@ -46,7 +47,7 @@
{ {
$object = new self(); $object = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? BotCommandScopeType::AllGroupChats;
return $object; return $object;
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\BotCommandScope; namespace TgBotLib\Objects\BotCommandScope;
use TgBotLib\Abstracts\BotCommandScopeType;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\BotCommandScope; use TgBotLib\Objects\BotCommandScope;
@ -46,7 +47,7 @@
{ {
$object = new self(); $object = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? BotCommandScopeType::AllPrivateChats;
return $object; return $object;
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\BotCommandScope; namespace TgBotLib\Objects\BotCommandScope;
use TgBotLib\Abstracts\BotCommandScopeType;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\BotCommandScope; use TgBotLib\Objects\BotCommandScope;
@ -62,8 +63,8 @@
{ {
$object = new self(); $object = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? BotCommandScopeType::Chat;
$object->chat_id = $data['chat_id']; $object->chat_id = $data['chat_id'] ?? null;
return $object; return $object;
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\BotCommandScope; namespace TgBotLib\Objects\BotCommandScope;
use TgBotLib\Abstracts\BotCommandScopeType;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\BotCommandScope; use TgBotLib\Objects\BotCommandScope;
@ -46,7 +47,7 @@
{ {
$object = new self(); $object = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? BotCommandScopeType::ChatAdministrators;
return $object; return $object;
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\BotCommandScope; namespace TgBotLib\Objects\BotCommandScope;
use TgBotLib\Abstracts\BotCommandScopeType;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\BotCommandScope; use TgBotLib\Objects\BotCommandScope;
@ -77,9 +78,11 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->type = $data['type'];
$object->chat_id = $data['chat_id']; $object->type = $data['type'] ?? BotCommandScopeType::ChatMember;
$object->user_id = $data['user_id']; $object->chat_id = $data['chat_id'] ?? null;
$object->user_id = $data['user_id'] ?? null;
return $object; return $object;
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\BotCommandScope; namespace TgBotLib\Objects\BotCommandScope;
use TgBotLib\Abstracts\BotCommandScopeType;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\BotCommandScope; use TgBotLib\Objects\BotCommandScope;
@ -46,7 +47,7 @@
{ {
$object = new self(); $object = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? BotCommandScopeType::Default;
return $object; return $object;
} }

View file

@ -127,8 +127,8 @@
{ {
return [ return [
'id' => $this->id, 'id' => $this->id,
'from' => ($this->from instanceof User) ? $this->from->toArray() : null, 'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : null,
'message' => ($this->message instanceof Message) ? $this->message->toArray() : null, 'message' => ($this->message instanceof ObjectTypeInterface) ? $this->message->toArray() : null,
'inline_message_id' => $this->inline_message_id, 'inline_message_id' => $this->inline_message_id,
'chat_instance' => $this->chat_instance, 'chat_instance' => $this->chat_instance,
'data' => $this->data, 'data' => $this->data,
@ -146,11 +146,11 @@
{ {
$object = new self(); $object = new self();
$object->id = $data['id']; $object->id = $data['id'] ?? null;
$object->from = isset($data['from']) ? User::fromArray($data['from']) : null; $object->from = isset($data['from']) ? User::fromArray($data['from']) : null;
$object->message = isset($data['message']) ? Message::fromArray($data['message']) : null; $object->message = isset($data['message']) ? Message::fromArray($data['message']) : null;
$object->inline_message_id = $data['inline_message_id'] ?? 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->data = $data['data'] ?? null;
$object->game_short_name = $data['game_short_name'] ?? null; $object->game_short_name = $data['game_short_name'] ?? null;

View file

@ -218,7 +218,7 @@
* @see https://telegram.org/blog/topics-in-groups-collectible-usernames#topics-in-groups * @see https://telegram.org/blog/topics-in-groups-collectible-usernames#topics-in-groups
* @return bool * @return bool
*/ */
public function isIsForum(): bool public function isForum(): bool
{ {
return $this->is_forum; return $this->is_forum;
} }
@ -391,7 +391,7 @@
* @see https://core.telegram.org/bots/api#getchat * @see https://core.telegram.org/bots/api#getchat
* @return bool * @return bool
*/ */
public function isHasAggressiveAntiSpamEnabled(): bool public function hasAggressiveAntiSpamEnabled(): bool
{ {
return $this->has_aggressive_anti_spam_enabled; return $this->has_aggressive_anti_spam_enabled;
} }
@ -403,7 +403,7 @@
* @see https://core.telegram.org/bots/api#getchat * @see https://core.telegram.org/bots/api#getchat
* @return bool * @return bool
*/ */
public function isHasHiddenMembers(): bool public function hasHiddenMembers(): bool
{ {
return $this->has_hidden_members; return $this->has_hidden_members;
} }
@ -414,7 +414,7 @@
* @see https://core.telegram.org/bots/api#getchat * @see https://core.telegram.org/bots/api#getchat
* @return bool * @return bool
*/ */
public function isHasProtectedContent(): bool public function hasProtectedContent(): bool
{ {
return $this->has_protected_content; return $this->has_protected_content;
} }
@ -479,7 +479,7 @@
'first_name' => $this->first_name, 'first_name' => $this->first_name,
'last_name' => $this->last_name, 'last_name' => $this->last_name,
'is_forum' => $this->is_forum, '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, 'active_usernames' => $this->active_usernames,
'emoji_status_custom_emoji_id' => $this->emoji_status_custom_emoji_id, 'emoji_status_custom_emoji_id' => $this->emoji_status_custom_emoji_id,
'bio' => $this->bio, 'bio' => $this->bio,
@ -489,8 +489,8 @@
'join_by_request' => $this->join_by_request, 'join_by_request' => $this->join_by_request,
'description' => $this->description, 'description' => $this->description,
'invite_link' => $this->invite_link, 'invite_link' => $this->invite_link,
'pinned_message' => ($this->pinned_message instanceof Message) ? $this->pinned_message->toArray() : null, 'pinned_message' => ($this->pinned_message instanceof ObjectTypeInterface) ? $this->pinned_message->toArray() : null,
'permissions' => ($this->permissions instanceof ChatPermissions) ? $this->permissions->toArray() : null, 'permissions' => ($this->permissions instanceof ObjectTypeInterface) ? $this->permissions->toArray() : null,
'slow_mode_delay' => $this->slow_mode_delay, 'slow_mode_delay' => $this->slow_mode_delay,
'message_auto_delete_time' => $this->message_auto_delete_time, 'message_auto_delete_time' => $this->message_auto_delete_time,
'has_aggressive_anti_spam_enabled' => $this->has_aggressive_anti_spam_enabled, 'has_aggressive_anti_spam_enabled' => $this->has_aggressive_anti_spam_enabled,
@ -499,7 +499,7 @@
'sticker_set_name' => $this->sticker_set_name, 'sticker_set_name' => $this->sticker_set_name,
'can_set_sticker_set' => $this->can_set_sticker_set, 'can_set_sticker_set' => $this->can_set_sticker_set,
'linked_chat_id' => $this->linked_chat_id, '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 = new self();
$object->id = @$data['id']; $object->id = $data['id'] ?? null;
$object->type = @$data['type']; $object->type = $data['type'] ?? null;
$object->title = @$data['title'] ?? null; $object->title = $data['title'] ?? null;
$object->username = @$data['username'] ?? null; $object->username = $data['username'] ?? null;
$object->first_name = @$data['first_name'] ?? null; $object->first_name = $data['first_name'] ?? null;
$object->last_name = @$data['last_name'] ?? null; $object->last_name = $data['last_name'] ?? null;
$object->is_forum = @$data['is_forum'] ?? null; $object->is_forum = $data['is_forum'] ?? null;
$object->photo = isset($data['photo']) ? ChatPhoto::fromArray($data['photo']) : null; $object->photo = isset($data['photo']) ? ChatPhoto::fromArray($data['photo']) : null;
$object->active_usernames = @$data['active_usernames'] ?? null; $object->active_usernames = $data['active_usernames'] ?? null;
$object->emoji_status_custom_emoji_id = @$data['emoji_status_custom_emoji_id'] ?? null; $object->emoji_status_custom_emoji_id = $data['emoji_status_custom_emoji_id'] ?? null;
$object->bio = @$data['bio'] ?? null; $object->bio = $data['bio'] ?? null;
$object->has_private_forwards = @$data['has_private_forwards'] ?? 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->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_to_send_messages = $data['join_to_send_messages'] ?? null;
$object->join_by_request = @$data['join_by_request'] ?? null; $object->join_by_request = $data['join_by_request'] ?? null;
$object->description = @$data['description'] ?? null; $object->description = $data['description'] ?? null;
$object->invite_link = @$data['invite_link'] ?? null; $object->invite_link = $data['invite_link'] ?? null;
$object->pinned_message = isset($data['pinned_message']) ? Message::fromArray($data['pinned_message']) : 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->permissions = isset($data['permissions']) ? ChatPermissions::fromArray($data['permissions']) : null;
$object->slow_mode_delay = @$data['slow_mode_delay'] ?? null; $object->slow_mode_delay = $data['slow_mode_delay'] ?? null;
$object->message_auto_delete_time = @$data['message_auto_delete_time'] ?? 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_aggressive_anti_spam_enabled = $data['has_aggressive_anti_spam_enabled'] ?? null;
$object->has_hidden_members = @$data['has_hidden_members'] ?? null; $object->has_hidden_members = $data['has_hidden_members'] ?? null;
$object->has_protected_content = @$data['has_protected_content'] ?? null; $object->has_protected_content = $data['has_protected_content'] ?? null;
$object->sticker_set_name = @$data['sticker_set_name'] ?? null; $object->sticker_set_name = $data['sticker_set_name'] ?? null;
$object->can_set_sticker_set = @$data['can_set_sticker_set'] ?? null; $object->can_set_sticker_set = $data['can_set_sticker_set'] ?? null;
$object->linked_chat_id = @$data['linked_chat_id'] ?? null; $object->linked_chat_id = $data['linked_chat_id'] ?? null;
$object->location = isset($data['location']) ? ChatLocation::fromArray($data['location']) : null; $object->location = isset($data['location']) ? ChatLocation::fromArray($data['location']) : null;
return $object; return $object;

View file

@ -73,7 +73,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsAnonymous(): bool public function isAnonymous(): bool
{ {
return $this->is_anonymous; return $this->is_anonymous;
} }
@ -85,7 +85,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageChat(): bool public function canManageChat(): bool
{ {
return $this->can_manage_chat; return $this->can_manage_chat;
} }
@ -95,7 +95,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanDeleteMessages(): bool public function canDeleteMessages(): bool
{ {
return $this->can_delete_messages; return $this->can_delete_messages;
} }
@ -105,7 +105,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageVideoChats(): bool public function canManageVideoChats(): bool
{ {
return $this->can_manage_video_chats; return $this->can_manage_video_chats;
} }
@ -115,7 +115,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanRestrictMembers(): bool public function canRestrictMembers(): bool
{ {
return $this->can_restrict_members; return $this->can_restrict_members;
} }
@ -127,7 +127,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPromoteMembers(): bool public function canPromoteMembers(): bool
{ {
return $this->can_promote_members; return $this->can_promote_members;
} }
@ -137,7 +137,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanChangeInfo(): bool public function canChangeInfo(): bool
{ {
return $this->can_change_info; return $this->can_change_info;
} }
@ -147,7 +147,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanInviteUsers(): bool public function canInviteUsers(): bool
{ {
return $this->can_invite_users; return $this->can_invite_users;
} }
@ -157,7 +157,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPostMessages(): bool public function canPostMessages(): bool
{ {
return $this->can_post_messages; return $this->can_post_messages;
} }
@ -167,7 +167,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanEditMessages(): bool public function canEditMessages(): bool
{ {
return $this->can_edit_messages; return $this->can_edit_messages;
} }
@ -177,7 +177,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPinMessages(): bool public function canPinMessages(): bool
{ {
return $this->can_pin_messages; return $this->can_pin_messages;
} }
@ -187,7 +187,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageTopics(): bool public function canManageTopics(): bool
{ {
return $this->can_manage_topics; return $this->can_manage_topics;
} }
@ -220,6 +220,7 @@
* *
* @param array $data * @param array $data
* @return ObjectTypeInterface * @return ObjectTypeInterface
* @noinspection DuplicatedCode
*/ */
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {

View file

@ -79,7 +79,7 @@
* *
* @return bool * @return bool
*/ */
public function isCreatesJoinRequest(): bool public function createsJoinRequest(): bool
{ {
return $this->creates_join_request; return $this->creates_join_request;
} }
@ -89,7 +89,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsPrimary(): bool public function isPrimary(): bool
{ {
return $this->is_primary; return $this->is_primary;
} }
@ -99,7 +99,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsRevoked(): bool public function isRevoked(): bool
{ {
return $this->is_revoked; return $this->is_revoked;
} }
@ -174,15 +174,15 @@
{ {
$object = new self(); $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->creator = isset($data['creator']) ? User::fromArray($data['creator']) : null;
$object->creates_join_request = $data['creates_join_request']; $object->creates_join_request = $data['creates_join_request'] ?? null;
$object->is_primary = $data['is_primary']; $object->is_primary = $data['is_primary'] ?? null;
$object->is_revoked = $data['is_revoked']; $object->is_revoked = $data['is_revoked'] ?? null;
$object->name = $data['name']; $object->name = $data['name'] ?? null;
$object->expire_date = $data['expire_date']; $object->expire_date = $data['expire_date'] ?? null;
$object->member_limit = $data['member_limit']; $object->member_limit = $data['member_limit'] ?? null;
$object->pending_join_request_count = $data['pending_join_request_count']; $object->pending_join_request_count = $data['pending_join_request_count'] ?? null;
return $object; return $object;
} }

View file

@ -110,12 +110,12 @@
public function toArray(): array public function toArray(): array
{ {
return [ return [
'chat' => ($this->chat instanceof Chat) ? $this->chat->toArray() : $this->chat, 'chat' => ($this->chat instanceof ObjectTypeInterface) ? $this->chat->toArray() : $this->chat,
'from' => ($this->from instanceof User) ? $this->from->toArray() : $this->from, 'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : $this->from,
'user_chat_id' => $this->user_chat_id, 'user_chat_id' => $this->user_chat_id,
'date' => $this->date, 'date' => $this->date,
'bio' => $this->bio, '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,
]; ];
} }

View file

@ -46,7 +46,7 @@
public function toArray(): array public function toArray(): array
{ {
return [ return [
'location' => ($this->location instanceof Location) ? $this->location->toArray() : $this->location, 'location' => ($this->location instanceof ObjectTypeInterface) ? $this->location->toArray() : $this->location,
'address' => $this->address, 'address' => $this->address,
]; ];
} }
@ -62,7 +62,7 @@
$object = new self(); $object = new self();
$object->location = isset($data['location']) ? Location::fromArray($data['location']) : null; $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; return $object;
} }

View file

@ -183,7 +183,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsMember(): bool public function isMember(): bool
{ {
return $this->is_member; return $this->is_member;
} }
@ -193,7 +193,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsAnonymous(): bool public function isAnonymous(): bool
{ {
return $this->is_anonymous; return $this->is_anonymous;
} }
@ -203,7 +203,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendMessages(): bool public function canSendMessages(): bool
{ {
return $this->can_send_messages; return $this->can_send_messages;
} }
@ -213,7 +213,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendAudios(): bool public function canSendAudios(): bool
{ {
return $this->can_send_audios; return $this->can_send_audios;
} }
@ -223,7 +223,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendDocuments(): bool public function canSendDocuments(): bool
{ {
return $this->can_send_documents; return $this->can_send_documents;
} }
@ -233,7 +233,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendPhotos(): bool public function canSendPhotos(): bool
{ {
return $this->can_send_photos; return $this->can_send_photos;
} }
@ -243,7 +243,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendVideos(): bool public function canSendVideos(): bool
{ {
return $this->can_send_videos; return $this->can_send_videos;
} }
@ -253,7 +253,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendVideoNotes(): bool public function canSendVideoNotes(): bool
{ {
return $this->can_send_video_notes; return $this->can_send_video_notes;
} }
@ -263,7 +263,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendVoiceNotes(): bool public function canSendVoiceNotes(): bool
{ {
return $this->can_send_voice_notes; return $this->can_send_voice_notes;
} }
@ -273,7 +273,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendPolls(): bool public function canSendPolls(): bool
{ {
return $this->can_send_polls; return $this->can_send_polls;
} }
@ -283,7 +283,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendOtherMessages(): bool public function canSendOtherMessages(): bool
{ {
return $this->can_send_other_messages; return $this->can_send_other_messages;
} }
@ -293,7 +293,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanAddWebPagePreviews(): bool public function canAddWebPagePreviews(): bool
{ {
return $this->can_add_web_page_previews; return $this->can_add_web_page_previews;
} }
@ -303,7 +303,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanChangeInfo(): bool public function canChangeInfo(): bool
{ {
return $this->can_change_info; return $this->can_change_info;
} }
@ -315,7 +315,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageChat(): bool public function canManageChat(): bool
{ {
return $this->can_manage_chat; return $this->can_manage_chat;
} }
@ -325,7 +325,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanDeleteMessages(): bool public function canDeleteMessages(): bool
{ {
return $this->can_delete_messages; return $this->can_delete_messages;
} }
@ -335,7 +335,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageVideoChats(): bool public function canManageVideoChats(): bool
{ {
return $this->can_manage_video_chats; return $this->can_manage_video_chats;
} }
@ -345,7 +345,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanRestrictMembers(): bool public function canRestrictMembers(): bool
{ {
return $this->can_restrict_members; return $this->can_restrict_members;
} }
@ -357,7 +357,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPromoteMembers(): bool public function canPromoteMembers(): bool
{ {
return $this->can_promote_members; return $this->can_promote_members;
} }
@ -367,7 +367,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanInviteUsers(): bool public function canInviteUsers(): bool
{ {
return $this->can_invite_users; return $this->can_invite_users;
} }
@ -377,7 +377,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPostMessages(): bool public function canPostMessages(): bool
{ {
return $this->can_post_messages; return $this->can_post_messages;
} }
@ -387,7 +387,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanEditMessages(): bool public function canEditMessages(): bool
{ {
return $this->can_edit_messages; return $this->can_edit_messages;
} }
@ -397,7 +397,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPinMessages(): bool public function canPinMessages(): bool
{ {
return $this->can_pin_messages; return $this->can_pin_messages;
} }
@ -407,7 +407,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageTopics(): bool public function canManageTopics(): bool
{ {
return $this->can_manage_topics; return $this->can_manage_topics;
} }
@ -417,7 +417,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanBeEdited(): bool public function canBeEdited(): bool
{ {
return $this->can_be_edited; return $this->can_be_edited;
} }
@ -441,7 +441,7 @@
{ {
return [ return [
'status' => $this->status, '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, 'custom_title' => $this->custom_title,
'is_member' => $this->is_member, 'is_member' => $this->is_member,
'is_anonymous' => $this->is_anonymous, 'is_anonymous' => $this->is_anonymous,
@ -476,39 +476,40 @@
* *
* @param array $data * @param array $data
* @return ObjectTypeInterface * @return ObjectTypeInterface
* @noinspection DuplicatedCode
*/ */
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new static(); $object = new static();
$object->status = @$data['status']; $object->status = $data['status'] ?? null;
$object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null;
$object->custom_title = @$data['custom_title'] ?? null; $object->custom_title = $data['custom_title'] ?? null;
$object->is_member = @$data['is_member'] ?? false; $object->is_member = $data['is_member'] ?? false;
$object->is_anonymous = @$data['is_anonymous'] ?? false; $object->is_anonymous = $data['is_anonymous'] ?? false;
$object->can_send_messages = @$data['can_send_messages'] ?? false; $object->can_send_messages = $data['can_send_messages'] ?? false;
$object->can_send_audios = @$data['can_send_audios'] ?? false; $object->can_send_audios = $data['can_send_audios'] ?? false;
$object->can_send_documents = @$data['can_send_documents'] ?? false; $object->can_send_documents = $data['can_send_documents'] ?? false;
$object->can_send_photos = @$data['can_send_photos'] ?? false; $object->can_send_photos = $data['can_send_photos'] ?? false;
$object->can_send_videos = @$data['can_send_videos'] ?? false; $object->can_send_videos = $data['can_send_videos'] ?? false;
$object->can_send_video_notes = @$data['can_send_video_notes'] ?? 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_voice_notes = $data['can_send_voice_notes'] ?? false;
$object->can_send_polls = @$data['can_send_polls'] ?? false; $object->can_send_polls = $data['can_send_polls'] ?? false;
$object->can_send_other_messages = @$data['can_send_other_messages'] ?? 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_add_web_page_previews = $data['can_add_web_page_previews'] ?? false;
$object->can_change_info = @$data['can_change_info'] ?? false; $object->can_change_info = $data['can_change_info'] ?? false;
$object->can_manage_chat = @$data['can_manage_chat'] ?? false; $object->can_manage_chat = $data['can_manage_chat'] ?? false;
$object->can_delete_messages = @$data['can_delete_messages'] ?? false; $object->can_delete_messages = $data['can_delete_messages'] ?? false;
$object->can_manage_video_chats = @$data['can_manage_video_chats'] ?? false; $object->can_manage_video_chats = $data['can_manage_video_chats'] ?? false;
$object->can_restrict_members = @$data['can_restrict_members'] ?? false; $object->can_restrict_members = $data['can_restrict_members'] ?? false;
$object->can_promote_members = @$data['can_promote_members'] ?? false; $object->can_promote_members = $data['can_promote_members'] ?? false;
$object->can_invite_users = @$data['can_invite_users'] ?? false; $object->can_invite_users = $data['can_invite_users'] ?? false;
$object->can_post_messages = @$data['can_post_messages'] ?? false; $object->can_post_messages = $data['can_post_messages'] ?? false;
$object->can_edit_messages = @$data['can_edit_messages'] ?? false; $object->can_edit_messages = $data['can_edit_messages'] ?? false;
$object->can_pin_messages = @$data['can_pin_messages'] ?? false; $object->can_pin_messages = $data['can_pin_messages'] ?? false;
$object->can_manage_topics = @$data['can_manage_topics'] ?? false; $object->can_manage_topics = $data['can_manage_topics'] ?? false;
$object->can_be_edited = @$data['can_be_edited'] ?? false; $object->can_be_edited = $data['can_be_edited'] ?? false;
$object->until_date = @$data['until_date'] ?? null; $object->until_date = $data['until_date'] ?? null;
return $object; return $object;
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\ChatMember; namespace TgBotLib\Objects\ChatMember;
use TgBotLib\Abstracts\ChatMemberStatus;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\ChatMember; use TgBotLib\Objects\ChatMember;
use TgBotLib\Objects\User; use TgBotLib\Objects\User;
@ -115,7 +116,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanBeEdited(): bool public function canBeEdited(): bool
{ {
return $this->can_be_edited; return $this->can_be_edited;
} }
@ -125,7 +126,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsAnonymous(): bool public function isAnonymous(): bool
{ {
return $this->is_anonymous; return $this->is_anonymous;
} }
@ -137,7 +138,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageChat(): bool public function canManageChat(): bool
{ {
return $this->can_manage_chat; return $this->can_manage_chat;
} }
@ -147,7 +148,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanDeleteMessages(): bool public function canDeleteMessages(): bool
{ {
return $this->can_delete_messages; return $this->can_delete_messages;
} }
@ -157,7 +158,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageVideoChats(): bool public function canManageVideoChats(): bool
{ {
return $this->can_manage_video_chats; return $this->can_manage_video_chats;
} }
@ -167,7 +168,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanRestrictMembers(): bool public function canRestrictMembers(): bool
{ {
return $this->can_restrict_members; return $this->can_restrict_members;
} }
@ -179,7 +180,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPromoteMembers(): bool public function canPromoteMembers(): bool
{ {
return $this->can_promote_members; return $this->can_promote_members;
} }
@ -189,7 +190,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanChangeInfo(): bool public function canChangeInfo(): bool
{ {
return $this->can_change_info; return $this->can_change_info;
} }
@ -199,7 +200,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanInviteUsers(): bool public function canInviteUsers(): bool
{ {
return $this->can_invite_users; return $this->can_invite_users;
} }
@ -209,7 +210,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPostMessages(): bool public function canPostMessages(): bool
{ {
return $this->can_post_messages; return $this->can_post_messages;
} }
@ -219,7 +220,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanEditMessages(): bool public function canEditMessages(): bool
{ {
return $this->can_edit_messages; return $this->can_edit_messages;
} }
@ -229,7 +230,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPinMessages(): bool public function canPinMessages(): bool
{ {
return $this->can_pin_messages; return $this->can_pin_messages;
} }
@ -239,7 +240,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageTopics(): bool public function canManageTopics(): bool
{ {
return $this->can_manage_topics; return $this->can_manage_topics;
} }
@ -291,22 +292,22 @@
{ {
$object = new self(); $object = new self();
$object->status = $data['status']; $object->status = $data['status'] ?? ChatMemberStatus::Administrator;
$object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null;
$object->can_be_edited = @$data['can_be_edited'] ?? false; $object->can_be_edited = $data['can_be_edited'] ?? false;
$object->is_anonymous = @$data['is_anonymous'] ?? false; $object->is_anonymous = $data['is_anonymous'] ?? false;
$object->can_manage_chat = @$data['can_manage_chat'] ?? false; $object->can_manage_chat = $data['can_manage_chat'] ?? false;
$object->can_delete_messages = @$data['can_delete_messages'] ?? false; $object->can_delete_messages = $data['can_delete_messages'] ?? false;
$object->can_manage_video_chats = @$data['can_manage_video_chats'] ?? false; $object->can_manage_video_chats = $data['can_manage_video_chats'] ?? false;
$object->can_restrict_members = @$data['can_restrict_members'] ?? false; $object->can_restrict_members = $data['can_restrict_members'] ?? false;
$object->can_promote_members = @$data['can_promote_members'] ?? false; $object->can_promote_members = $data['can_promote_members'] ?? false;
$object->can_change_info = @$data['can_change_info'] ?? false; $object->can_change_info = $data['can_change_info'] ?? false;
$object->can_invite_users = @$data['can_invite_users'] ?? false; $object->can_invite_users = $data['can_invite_users'] ?? false;
$object->can_post_messages = @$data['can_post_messages'] ?? false; $object->can_post_messages = $data['can_post_messages'] ?? false;
$object->can_edit_messages = @$data['can_edit_messages'] ?? false; $object->can_edit_messages = $data['can_edit_messages'] ?? false;
$object->can_pin_messages = @$data['can_pin_messages'] ?? false; $object->can_pin_messages = $data['can_pin_messages'] ?? false;
$object->can_manage_topics = @$data['can_manage_topics'] ?? false; $object->can_manage_topics = $data['can_manage_topics'] ?? false;
$object->custom_title = @$data['custom_title'] ?? null; $object->custom_title = $data['custom_title'] ?? null;
return $object; return $object;
} }
@ -323,19 +324,19 @@
$object->status = $chatMember->getStatus(); $object->status = $chatMember->getStatus();
$object->user = $chatMember->getUser(); $object->user = $chatMember->getUser();
$object->can_be_edited = $chatMember->isCanBeEdited(); $object->can_be_edited = $chatMember->canBeEdited();
$object->is_anonymous = $chatMember->isIsAnonymous(); $object->is_anonymous = $chatMember->isAnonymous();
$object->can_manage_chat = $chatMember->isCanManageChat(); $object->can_manage_chat = $chatMember->canManageChat();
$object->can_delete_messages = $chatMember->isCanDeleteMessages(); $object->can_delete_messages = $chatMember->canDeleteMessages();
$object->can_manage_video_chats = $chatMember->isCanManageVideoChats(); $object->can_manage_video_chats = $chatMember->canManageVideoChats();
$object->can_restrict_members = $chatMember->isCanRestrictMembers(); $object->can_restrict_members = $chatMember->canRestrictMembers();
$object->can_promote_members = $chatMember->isCanPromoteMembers(); $object->can_promote_members = $chatMember->canPromoteMembers();
$object->can_change_info = $chatMember->isCanChangeInfo(); $object->can_change_info = $chatMember->canChangeInfo();
$object->can_invite_users = $chatMember->isCanInviteUsers(); $object->can_invite_users = $chatMember->canInviteUsers();
$object->can_post_messages = $chatMember->isCanPostMessages(); $object->can_post_messages = $chatMember->canPostMessages();
$object->can_edit_messages = $chatMember->isCanEditMessages(); $object->can_edit_messages = $chatMember->canEditMessages();
$object->can_pin_messages = $chatMember->isCanPinMessages(); $object->can_pin_messages = $chatMember->canPinMessages();
$object->can_manage_topics = $chatMember->isCanManageTopics(); $object->can_manage_topics = $chatMember->canManageTopics();
$object->custom_title = $chatMember->getCustomTitle(); $object->custom_title = $chatMember->getCustomTitle();
return $object; return $object;

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\ChatMember; namespace TgBotLib\Objects\ChatMember;
use TgBotLib\Abstracts\ChatMemberStatus;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\ChatMember; use TgBotLib\Objects\ChatMember;
use TgBotLib\Objects\User; use TgBotLib\Objects\User;
@ -78,9 +79,10 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->status = $data['status'];
$object->status = $data['status'] ?? ChatMemberStatus::Kicked;
$object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $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; return $object;
} }
@ -94,6 +96,7 @@
public static function fromChatMember(ChatMember $chatMember): ChatMemberBanned public static function fromChatMember(ChatMember $chatMember): ChatMemberBanned
{ {
$object = new self(); $object = new self();
$object->status = $chatMember->getStatus(); $object->status = $chatMember->getStatus();
$object->user = $chatMember->getUser(); $object->user = $chatMember->getUser();
$object->until_date = $chatMember->getUntilDate(); $object->until_date = $chatMember->getUntilDate();

View file

@ -1,7 +1,10 @@
<?php <?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\ChatMember; namespace TgBotLib\Objects\ChatMember;
use TgBotLib\Abstracts\ChatMemberStatus;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\ChatMember; use TgBotLib\Objects\ChatMember;
use TgBotLib\Objects\User; use TgBotLib\Objects\User;
@ -60,8 +63,10 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->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; return $object;
} }
@ -74,8 +79,10 @@
public static function fromChatMember(ChatMember $chatMember): self public static function fromChatMember(ChatMember $chatMember): self
{ {
$object = new self(); $object = new self();
$object->status = $chatMember->getStatus(); $object->status = $chatMember->getStatus();
$object->user = $chatMember->getUser(); $object->user = $chatMember->getUser();
return $object; return $object;
} }
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\ChatMember; namespace TgBotLib\Objects\ChatMember;
use TgBotLib\Abstracts\ChatMemberStatus;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\ChatMember; use TgBotLib\Objects\ChatMember;
use TgBotLib\Objects\User; use TgBotLib\Objects\User;
@ -63,7 +64,7 @@
{ {
$object = new self(); $object = new self();
$object->status = $data['status']; $object->status = $data['status'] ?? ChatMemberStatus::Member;
$object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null;
return $object; return $object;

View file

@ -56,7 +56,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsAnonymous(): bool public function isAnonymous(): bool
{ {
return $this->is_anonymous; return $this->is_anonymous;
} }
@ -95,10 +95,12 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new ChatMemberOwner(); $object = new ChatMemberOwner();
$object->status = $data['status'] ?? ChatMemberStatus::Creator; $object->status = $data['status'] ?? ChatMemberStatus::Creator;
$object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null;
$object->is_anonymous = $data['is_anonymous'] ?? false; $object->is_anonymous = $data['is_anonymous'] ?? false;
$object->custom_title = $data['custom_title'] ?? null; $object->custom_title = $data['custom_title'] ?? null;
return $object; return $object;
} }
@ -111,10 +113,12 @@
public static function fromChatMember(ChatMember $chatMember): ChatMemberOwner public static function fromChatMember(ChatMember $chatMember): ChatMemberOwner
{ {
$object = new ChatMemberOwner(); $object = new ChatMemberOwner();
$object->status = $chatMember->getStatus(); $object->status = $chatMember->getStatus();
$object->user = $chatMember->getUser(); $object->user = $chatMember->getUser();
$object->is_anonymous = $chatMember->isIsAnonymous(); $object->is_anonymous = $chatMember->isAnonymous();
$object->custom_title = $chatMember->getCustomTitle(); $object->custom_title = $chatMember->getCustomTitle();
return $object; return $object;
} }
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\ChatMember; namespace TgBotLib\Objects\ChatMember;
use TgBotLib\Abstracts\ChatMemberStatus;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\ChatMember; use TgBotLib\Objects\ChatMember;
use TgBotLib\Objects\User; use TgBotLib\Objects\User;
@ -125,7 +126,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsMember(): bool public function isMember(): bool
{ {
return $this->is_member; return $this->is_member;
} }
@ -135,7 +136,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendMessages(): bool public function canSendMessages(): bool
{ {
return $this->can_send_messages; return $this->can_send_messages;
} }
@ -145,7 +146,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendAudios(): bool public function canSendAudios(): bool
{ {
return $this->can_send_audios; return $this->can_send_audios;
} }
@ -155,7 +156,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendDocuments(): bool public function canSendDocuments(): bool
{ {
return $this->can_send_documents; return $this->can_send_documents;
} }
@ -165,7 +166,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendPhotos(): bool public function canSendPhotos(): bool
{ {
return $this->can_send_photos; return $this->can_send_photos;
} }
@ -175,7 +176,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendVideos(): bool public function canSendVideos(): bool
{ {
return $this->can_send_videos; return $this->can_send_videos;
} }
@ -185,7 +186,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendVideoNotes(): bool public function canSendVideoNotes(): bool
{ {
return $this->can_send_video_notes; return $this->can_send_video_notes;
} }
@ -195,7 +196,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendVoiceNotes(): bool public function canSendVoiceNotes(): bool
{ {
return $this->can_send_voice_notes; return $this->can_send_voice_notes;
} }
@ -205,7 +206,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendPolls(): bool public function canSendPolls(): bool
{ {
return $this->can_send_polls; return $this->can_send_polls;
} }
@ -215,7 +216,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendOtherMessages(): bool public function canSendOtherMessages(): bool
{ {
return $this->can_send_other_messages; return $this->can_send_other_messages;
} }
@ -225,7 +226,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanAddWebPagePreviews(): bool public function canAddWebPagePreviews(): bool
{ {
return $this->can_add_web_page_previews; return $this->can_add_web_page_previews;
} }
@ -235,7 +236,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanChangeInfo(): bool public function canChangeInfo(): bool
{ {
return $this->can_change_info; return $this->can_change_info;
} }
@ -245,7 +246,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanInviteUsers(): bool public function canInviteUsers(): bool
{ {
return $this->can_invite_users; return $this->can_invite_users;
} }
@ -255,7 +256,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPinMessages(): bool public function canPinMessages(): bool
{ {
return $this->can_pin_messages; return $this->can_pin_messages;
} }
@ -265,7 +266,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageTopics(): bool public function canManageTopics(): bool
{ {
return $this->can_manage_topics; return $this->can_manage_topics;
} }
@ -314,29 +315,30 @@
* *
* @param array $data * @param array $data
* @return ObjectTypeInterface * @return ObjectTypeInterface
* @noinspection DuplicatedCode
*/ */
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new static(); $object = new static();
$object->status = $data['status']; $object->status = $data['status'] ?? ChatMemberStatus::Restricted;
$object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null;
$object->is_member = @$data['is_member'] ?? false; $object->is_member = $data['is_member'] ?? false;
$object->can_send_messages = @$data['can_send_messages'] ?? false; $object->can_send_messages = $data['can_send_messages'] ?? false;
$object->can_send_audios = @$data['can_send_audios'] ?? false; $object->can_send_audios = $data['can_send_audios'] ?? false;
$object->can_send_documents = @$data['can_send_documents'] ?? false; $object->can_send_documents = $data['can_send_documents'] ?? false;
$object->can_send_photos = @$data['can_send_photos'] ?? false; $object->can_send_photos = $data['can_send_photos'] ?? false;
$object->can_send_videos = @$data['can_send_videos'] ?? false; $object->can_send_videos = $data['can_send_videos'] ?? false;
$object->can_send_video_notes = @$data['can_send_video_notes'] ?? 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_voice_notes = $data['can_send_voice_notes'] ?? false;
$object->can_send_polls = @$data['can_send_polls'] ?? false; $object->can_send_polls = $data['can_send_polls'] ?? false;
$object->can_send_other_messages = @$data['can_send_other_messages'] ?? 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_add_web_page_previews = $data['can_add_web_page_previews'] ?? false;
$object->can_change_info = @$data['can_change_info'] ?? false; $object->can_change_info = $data['can_change_info'] ?? false;
$object->can_invite_users = @$data['can_invite_users'] ?? false; $object->can_invite_users = $data['can_invite_users'] ?? false;
$object->can_pin_messages = @$data['can_pin_messages'] ?? false; $object->can_pin_messages = $data['can_pin_messages'] ?? false;
$object->can_manage_topics = @$data['can_manage_topics'] ?? false; $object->can_manage_topics = $data['can_manage_topics'] ?? false;
$object->until_date = @$data['until_date'] ?? 0; $object->until_date = $data['until_date'] ?? 0;
return $object; return $object;
} }
@ -353,21 +355,21 @@
$object->status = $chatMember->getStatus(); $object->status = $chatMember->getStatus();
$object->user = $chatMember->getUser(); $object->user = $chatMember->getUser();
$object->is_member = $chatMember->isIsMember(); $object->is_member = $chatMember->isMember();
$object->can_send_messages = $chatMember->isCanSendMessages(); $object->can_send_messages = $chatMember->canSendMessages();
$object->can_send_audios = $chatMember->isCanSendAudios(); $object->can_send_audios = $chatMember->canSendAudios();
$object->can_send_documents = $chatMember->isCanSendDocuments(); $object->can_send_documents = $chatMember->canSendDocuments();
$object->can_send_photos = $chatMember->isCanSendPhotos(); $object->can_send_photos = $chatMember->canSendPhotos();
$object->can_send_videos = $chatMember->isCanSendVideos(); $object->can_send_videos = $chatMember->canSendVideos();
$object->can_send_video_notes = $chatMember->isCanSendVideoNotes(); $object->can_send_video_notes = $chatMember->canSendVideoNotes();
$object->can_send_voice_notes = $chatMember->isCanSendVoiceNotes(); $object->can_send_voice_notes = $chatMember->canSendVoiceNotes();
$object->can_send_polls = $chatMember->isCanSendPolls(); $object->can_send_polls = $chatMember->canSendPolls();
$object->can_send_other_messages = $chatMember->isCanSendOtherMessages(); $object->can_send_other_messages = $chatMember->canSendOtherMessages();
$object->can_add_web_page_previews = $chatMember->isCanAddWebPagePreviews(); $object->can_add_web_page_previews = $chatMember->canAddWebPagePreviews();
$object->can_change_info = $chatMember->isCanChangeInfo(); $object->can_change_info = $chatMember->canChangeInfo();
$object->can_invite_users = $chatMember->isCanInviteUsers(); $object->can_invite_users = $chatMember->canInviteUsers();
$object->can_pin_messages = $chatMember->isCanPinMessages(); $object->can_pin_messages = $chatMember->canPinMessages();
$object->can_manage_topics = $chatMember->isCanManageTopics(); $object->can_manage_topics = $chatMember->canManageTopics();
$object->until_date = $chatMember->getUntilDate(); $object->until_date = $chatMember->getUntilDate();
return $object; return $object;

View file

@ -128,7 +128,7 @@
$object->chat = isset($data['chat']) ? Chat::fromArray($data['chat']) : new Chat(); $object->chat = isset($data['chat']) ? Chat::fromArray($data['chat']) : new Chat();
$object->from = isset($data['from']) ? User::fromArray($data['from']) : new User(); $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->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->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; $object->invite_link = isset($data['invite_link']) ? ChatInviteLink::fromArray($data['invite_link']) : null;

View file

@ -83,7 +83,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendMessages(): bool public function canSendMessages(): bool
{ {
return $this->can_send_messages; return $this->can_send_messages;
} }
@ -93,7 +93,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendAudios(): bool public function canSendAudios(): bool
{ {
return $this->can_send_audios; return $this->can_send_audios;
} }
@ -103,7 +103,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendDocuments(): bool public function canSendDocuments(): bool
{ {
return $this->can_send_documents; return $this->can_send_documents;
} }
@ -113,7 +113,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendPhotos(): bool public function canSendPhotos(): bool
{ {
return $this->can_send_photos; return $this->can_send_photos;
} }
@ -123,7 +123,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendVideos(): bool public function canSendVideos(): bool
{ {
return $this->can_send_videos; return $this->can_send_videos;
} }
@ -133,7 +133,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendVideosNotes(): bool public function canSendVideosNotes(): bool
{ {
return $this->can_send_videos_notes; return $this->can_send_videos_notes;
} }
@ -143,7 +143,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendVoiceNotes(): bool public function canSendVoiceNotes(): bool
{ {
return $this->can_send_voice_notes; return $this->can_send_voice_notes;
} }
@ -153,7 +153,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendPolls(): bool public function canSendPolls(): bool
{ {
return $this->can_send_polls; return $this->can_send_polls;
} }
@ -163,7 +163,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanSendOtherMessages(): bool public function canSendOtherMessages(): bool
{ {
return $this->can_send_other_messages; return $this->can_send_other_messages;
} }
@ -173,7 +173,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanAddWebPagePreviews(): bool public function canAddWebPagePreviews(): bool
{ {
return $this->can_add_web_page_previews; return $this->can_add_web_page_previews;
} }
@ -184,7 +184,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanChangeInfo(): bool public function canChangeInfo(): bool
{ {
return $this->can_change_info; return $this->can_change_info;
} }
@ -194,7 +194,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanInviteUsers(): bool public function canInviteUsers(): bool
{ {
return $this->can_invite_users; return $this->can_invite_users;
} }
@ -204,7 +204,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanPinMessages(): bool public function canPinMessages(): bool
{ {
return $this->can_pin_messages; return $this->can_pin_messages;
} }
@ -215,7 +215,7 @@
* *
* @return bool * @return bool
*/ */
public function isCanManageTopics(): bool public function canManageTopics(): bool
{ {
return $this->can_manage_topics; return $this->can_manage_topics;
} }
@ -250,25 +250,26 @@
* *
* @param array $data * @param array $data
* @return ObjectTypeInterface * @return ObjectTypeInterface
* @noinspection DuplicatedCode
*/ */
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->can_send_messages = @$data['can_send_messages'] ?? false; $object->can_send_messages = $data['can_send_messages'] ?? false;
$object->can_send_audios = @$data['can_send_audios'] ?? false; $object->can_send_audios = $data['can_send_audios'] ?? false;
$object->can_send_documents = @$data['can_send_documents'] ?? false; $object->can_send_documents = $data['can_send_documents'] ?? false;
$object->can_send_photos = @$data['can_send_photos'] ?? false; $object->can_send_photos = $data['can_send_photos'] ?? false;
$object->can_send_videos = @$data['can_send_videos'] ?? false; $object->can_send_videos = $data['can_send_videos'] ?? false;
$object->can_send_videos_notes = @$data['can_send_videos_notes'] ?? 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_voice_notes = $data['can_send_voice_notes'] ?? false;
$object->can_send_polls = @$data['can_send_polls'] ?? false; $object->can_send_polls = $data['can_send_polls'] ?? false;
$object->can_send_other_messages = @$data['can_send_other_messages'] ?? 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_add_web_page_previews = $data['can_add_web_page_previews'] ?? false;
$object->can_change_info = @$data['can_change_info'] ?? false; $object->can_change_info = $data['can_change_info'] ?? false;
$object->can_invite_users = @$data['can_invite_users'] ?? false; $object->can_invite_users = $data['can_invite_users'] ?? false;
$object->can_pin_messages = @$data['can_pin_messages'] ?? false; $object->can_pin_messages = $data['can_pin_messages'] ?? false;
$object->can_manage_topics = @$data['can_manage_topics'] ?? false; $object->can_manage_topics = $data['can_manage_topics'] ?? false;
return $object; return $object;
} }

View file

@ -1,5 +1,7 @@
<?php <?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects; namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
@ -95,10 +97,10 @@
{ {
$object = new ChatPhoto(); $object = new ChatPhoto();
$object->small_file_id = $data['small_file_id']; $object->small_file_id = $data['small_file_id'] ?? null;
$object->small_file_unique_id = $data['small_file_unique_id']; $object->small_file_unique_id = $data['small_file_unique_id'] ?? null;
$object->big_file_id = $data['big_file_id']; $object->big_file_id = $data['big_file_id'] ?? null;
$object->big_file_unique_id = $data['big_file_unique_id']; $object->big_file_unique_id = $data['big_file_unique_id'] ?? null;
return $object; return $object;
} }

View file

@ -65,8 +65,8 @@
{ {
$object = new self(); $object = new self();
$object->request_id = @$data['request_id']; $object->request_id = $data['request_id'] ?? null;
$object->chat_id = @$data['chat_id']; $object->chat_id = $data['chat_id'] ?? null;
return $object; return $object;
} }

View file

@ -111,11 +111,11 @@
{ {
$object = new self(); $object = new self();
$object->phone_number = @$data['phone_number']; $object->phone_number = $data['phone_number'] ?? null;
$object->first_name = @$data['first_name']; $object->first_name = $data['first_name'] ?? null;
$object->last_name = @$data['last_name'] ?? null; $object->last_name = $data['last_name'] ?? null;
$object->user_id = @$data['user_id'] ?? null; $object->user_id = $data['user_id'] ?? null;
$object->vcard = @$data['vcard'] ?? null; $object->vcard = $data['vcard'] ?? null;
return $object; return $object;
} }

View file

@ -57,8 +57,8 @@
{ {
$object = new self(); $object = new self();
$object->emoji = @$data['emoji'] ?? null; $object->emoji = $data['emoji'] ?? null;
$object->value = @$data['value'] ?? null; $object->value = $data['value'] ?? null;
return $object; return $object;
} }

View file

@ -111,7 +111,7 @@
return [ return [
'file_id' => $this->file_id ?? null, 'file_id' => $this->file_id ?? null,
'file_unique_id' => $this->file_unique_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, 'file_name' => $this->file_name ?? null,
'mime_type' => $this->mime_type ?? null, 'mime_type' => $this->mime_type ?? null,
'file_size' => $this->file_size ?? null, 'file_size' => $this->file_size ?? null,
@ -127,8 +127,8 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->file_id = $data['file_id']; $object->file_id = $data['file_id'] ?? null;
$object->file_unique_id = $data['file_unique_id']; $object->file_unique_id = $data['file_unique_id'] ?? null;
$object->thumb = isset($data['thumb']) ? PhotoSize::fromArray($data['thumb']) : null; $object->thumb = isset($data['thumb']) ? PhotoSize::fromArray($data['thumb']) : null;
$object->file_name = $data['file_name'] ?? null; $object->file_name = $data['file_name'] ?? null;
$object->mime_type = $data['mime_type'] ?? null; $object->mime_type = $data['mime_type'] ?? null;

View file

@ -79,9 +79,9 @@
{ {
$object = new self(); $object = new self();
$object->data = @$data['data']; $object->data = $data['data'] ?? null;
$object->hash = @$data['hash']; $object->hash = $data['hash'] ?? null;
$object->secret = @$data['secret']; $object->secret = $data['secret'] ?? null;
return $object; return $object;
} }

View file

@ -192,27 +192,47 @@
'data' => $this->data, 'data' => $this->data,
'phone_number' => $this->phone_number, 'phone_number' => $this->phone_number,
'email' => $this->email, 'email' => $this->email,
'files' => array_map(function (PassportFile $file) 'files' => is_array($this->files) ? array_map(function ($file)
{ {
return $file->toArray(); if($file instanceof PassportFile)
}, $this->files), {
'front_side' => array_map(function (PassportFile $file) return $file->toArray();
}
return $file;
}, $this->files) : null,
'front_side' => is_array($this->front_side) ? array_map(function ($file)
{ {
return $file->toArray(); if($file instanceof PassportFile)
}, $this->front_side), {
'reverse_side' => array_map(function (PassportFile $file) return $file->toArray();
}
return $file;
}, $this->front_side) : null,
'reverse_side' => is_array($this->reverse_side) ? array_map(function ($file)
{ {
return $file->toArray(); if($file instanceof PassportFile)
}, $this->reverse_side), {
'selfie' => array_map(function (PassportFile $file) return $file->toArray();
}
return $file;
}, $this->reverse_side) : null,
'selfie' => is_array($this->selfie) ? array_map(function ($file)
{ {
return $file->toArray(); if($file instanceof PassportFile)
}, $this->selfie), {
'translation' => array_map(function (PassportFile $file) return $file->toArray();
}
return $file;
}, $this->selfie) : null,
'translation' => is_array($this->translation) ? array_map(function ($file)
{ {
return $file->toArray(); if($file instanceof PassportFile)
}, $this->translation), {
'hash' => $this->hash, return $file->toArray();
}
return $file;
}, $this->translation) : null,
'hash' => $this->hash
]; ];
} }
@ -230,26 +250,26 @@
$object->data = $data['data'] ?? null; $object->data = $data['data'] ?? null;
$object->phone_number = $data['phone_number'] ?? null; $object->phone_number = $data['phone_number'] ?? null;
$object->email = $data['email'] ?? 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); return PassportFile::fromArray($file);
}, $data['files'] ?? []); }, $data['files'] ?? []) : null;
$object->front_side = array_map(function (array $file) $object->front_side = isset($data['front_side']) ? array_map(function (array $file)
{ {
return PassportFile::fromArray($file); return PassportFile::fromArray($file);
}, $data['front_side'] ?? []); }, $data['front_side'] ?? []) : null;
$object->reverse_side = array_map(function (array $file) $object->reverse_side = isset($data['reverse_side']) ? array_map(function (array $file)
{ {
return PassportFile::fromArray($file); return PassportFile::fromArray($file);
}, $data['reverse_side'] ?? []); }, $data['reverse_side'] ?? []) : null;
$object->selfie = array_map(function (array $file) $object->selfie = isset($data['selfie']) ? array_map(function (array $file)
{ {
return PassportFile::fromArray($file); return PassportFile::fromArray($file);
}, $data['selfie'] ?? []); }, $data['selfie'] ?? []) : null;
$object->translation = array_map(function (array $file) $object->translation = isset($data['translation']) ? array_map(function (array $file)
{ {
return PassportFile::fromArray($file); return PassportFile::fromArray($file);
}, $data['translation'] ?? []); }, $data['translation'] ?? []) : null;
$object->hash = $data['hash']; $object->hash = $data['hash'];
return $object; return $object;

View file

@ -81,8 +81,8 @@
return [ return [
'file_id' => $this->file_id, 'file_id' => $this->file_id,
'file_unique_id' => $this->file_unique_id, 'file_unique_id' => $this->file_unique_id,
'file_size' => $this->file_size ?? null, 'file_size' => $this->file_size,
'file_path' => $this->file_path ?? null, 'file_path' => $this->file_path
]; ];
} }
@ -95,10 +95,10 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->file_id = @$data['file_id']; $object->file_id = $data['file_id'] ?? null;
$object->file_unique_id = @$data['file_unique_id']; $object->file_unique_id = $data['file_unique_id'] ?? null;
$object->file_size = @$data['file_size'] ?? null; $object->file_size = $data['file_size'] ?? null;
$object->file_path = @$data['file_path'] ?? null; $object->file_path = $data['file_path'] ?? null;
return $object; return $object;
} }
} }

View file

@ -79,9 +79,9 @@
{ {
$object = new self(); $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->inline_field_placeholder = $data['inline_field_placeholder'] ?? null;
$object->selective = $data['selective']; $object->selective = $data['selective'] ?? false;
return $object; return $object;
} }

View file

@ -93,10 +93,10 @@
{ {
$object = new self(); $object = new self();
$object->message_thread_id = $data['message_thread_id']; $object->message_thread_id = $data['message_thread_id'] ?? null;
$object->name = $data['name']; $object->name = $data['name'] ?? null;
$object->icon_color = $data['icon_color']; $object->icon_color = $data['icon_color'] ?? null;
$object->icon_custom_emoji_id = @$data['icon_custom_emoji_id'] ?: null; $object->icon_custom_emoji_id = $data['icon_custom_emoji_id'] ?? null;
return $object; return $object;
} }

View file

@ -1,5 +1,7 @@
<?php <?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects; namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
@ -74,9 +76,10 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->name = @$data['name'];
$object->icon_color = @$data['icon_color']; $object->name = $data['name'] ?? null;
$object->icon_custom_emoji_id = @$data['icon_custom_emoji_id'] ?? null; $object->icon_color = $data['icon_color'] ?? null;
$object->icon_custom_emoji_id = $data['icon_custom_emoji_id'] ?? null;
return $object; return $object;
} }

View file

@ -62,8 +62,8 @@
{ {
$object = new self(); $object = new self();
$object->name = @$data['name'] ?? null; $object->name = $data['name'] ?? null;
$object->icon_custom_emoji_id = @$data['icon_custom_emoji_id'] ?? null; $object->icon_custom_emoji_id = $data['icon_custom_emoji_id'] ?? null;
return $object; return $object;
} }

View file

@ -109,31 +109,17 @@
*/ */
public function toArray(): array 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 [ return [
'title' => $this->title, 'title' => $this->title,
'description' => $this->description, 'description' => $this->description,
'photo' => $photo, 'photo' => isset($this->photo) ? array_map(function ($photo) {
return $photo->toArray();
}, $this->photo) : null,
'text' => $this->text, 'text' => $this->text,
'text_entities' => $text_entities, 'text_entities' => isset($this->text_entities) ? array_map(function ($text_entity) {
'animation' => ($this->animation instanceof Animation) ? $this->animation->toArray() : null, return $text_entity->toArray();
}, $this->text_entities) : null,
'animation' => ($this->animation instanceof ObjectTypeInterface) ? $this->animation->toArray() : null,
]; ];
} }
@ -147,28 +133,15 @@
{ {
$object = new self(); $object = new self();
$photo = null; $object->description = $data['description'] ?? null;
if ($data['photo']) $object->title = $data['title'] ?? null;
{ $object->photo = isset($data['photo']) && is_array($data['photo']) ? array_map(function ($photo) {
foreach ($data['photo'] as $photo_item) return PhotoSize::fromArray($photo);
{ }, $data['photo']) : null;
$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->text = $data['text'] ?? 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; $object->animation = ($data['animation']) ? Animation::fromArray($data['animation']) : null;
return $object; return $object;

View file

@ -173,11 +173,11 @@
'text' => $this->text ?? null, 'text' => $this->text ?? null,
'url' => $this->url ?? null, 'url' => $this->url ?? null,
'callback_data' => $this->callback_data ?? null, 'callback_data' => $this->callback_data ?? null,
'web_app' => ($this->web_app instanceof WebAppInfo) ? $this->web_app->toArray() : null, 'web_app' => ($this->web_app instanceof ObjectTypeInterface) ? $this->web_app->toArray() : null,
'login_url' => ($this->login_url instanceof LoginUrl) ? $this->login_url->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' => $this->switch_inline_query ?? null,
'switch_inline_query_current_chat' => $this->switch_inline_query_current_chat ?? 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 'pay' => $this->pay ?? null
]; ];
} }
@ -195,11 +195,11 @@
$object->text = $data['text'] ?? null; $object->text = $data['text'] ?? null;
$object->url = $data['url'] ?? null; $object->url = $data['url'] ?? null;
$object->callback_data = $data['callback_data'] ?? null; $object->callback_data = $data['callback_data'] ?? null;
$object->web_app = ($data['web_app'] ?? null) ? WebAppInfo::fromArray($data['web_app']) : null; $object->web_app = isset($data['web_app']) && is_array($data['web_app']) ? WebAppInfo::fromArray($data['web_app']) : null;
$object->login_url = ($data['login_url'] ?? null) ? LoginUrl::fromArray($data['login_url']) : 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 = $data['switch_inline_query'] ?? null;
$object->switch_inline_query_current_chat = $data['switch_inline_query_current_chat'] ?? 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; $object->pay = $data['pay'] ?? null;
return $object; return $object;

View file

@ -27,13 +27,22 @@
/** /**
* Returns an array representation of the object * Returns an array representation of the object
* *
* @return InlineKeyboardButton[][][] * @return array[][]
*/ */
public function toArray(): array public function toArray(): array
{ {
return [ $data = [];
'inline_keyboard' => $this->inline_keyboard,
]; 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 public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $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; return $object;
} }

View file

@ -212,7 +212,7 @@
* *
* @return bool * @return bool
*/ */
public function isHasSpoiler(): bool public function hasSpoiler(): bool
{ {
return $this->has_spoiler; return $this->has_spoiler;
} }
@ -235,23 +235,15 @@
*/ */
public function toArray(): array 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 [ return [
'type' => $this->type, 'type' => $this->type,
'media' => $this->media, 'media' => $this->media,
'thumb' => $this->thumb, 'thumb' => $this->thumb,
'caption' => $this->caption, 'caption' => $this->caption,
'parse_mode' => $this->parse_mode, '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, 'width' => $this->width,
'height' => $this->height, 'height' => $this->height,
'duration' => $this->duration, 'duration' => $this->duration,
@ -271,31 +263,24 @@
*/ */
public static function fromArray(array $data): ObjectTypeInterface 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 = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? null;
$object->media = $data['media']; $object->media = $data['media'] ?? null;
$object->thumb = @$data['thumb'] ?? null; $object->thumb = $data['thumb'] ?? null;
$object->caption = @$data['caption'] ?? null; $object->caption = $data['caption'] ?? null;
$object->parse_mode = @$data['parse_mode'] ?? null; $object->parse_mode = $data['parse_mode'] ?? null;
$object->caption_entities = $caption_entities; $object->caption_entities = isset($data['caption_entities']) && is_array($data['caption_entities']) ? array_map(function($entity)
$object->width = @$data['width'] ?? null; {
$object->height = @$data['height'] ?? null; return MessageEntity::fromArray($entity);
$object->duration = @$data['duration'] ?? null; }, $data['caption_entities']) : null;
$object->performer = @$data['performer'] ?? null; $object->width = $data['width'] ?? null;
$object->title = @$data['title'] ?? null; $object->height = $data['height'] ?? null;
$object->supports_streaming = @$data['supports_streaming'] ?? false; $object->duration = $data['duration'] ?? null;
$object->has_spoiler = @$data['has_spoiler'] ?? false; $object->performer = $data['performer'] ?? null;
$object->disable_content_type_detection = @$data['disable_content_type_detection'] ?? false; $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; return $object;
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\InputMedia; namespace TgBotLib\Objects\InputMedia;
use TgBotLib\Abstracts\InputMediaType;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\InputMedia; use TgBotLib\Objects\InputMedia;
use TgBotLib\Objects\MessageEntity; use TgBotLib\Objects\MessageEntity;
@ -61,6 +62,8 @@
private $has_spoiler; private $has_spoiler;
/** /**
* Type of the result, must be animation
*
* @return string * @return string
*/ */
public function getType(): string public function getType(): string
@ -163,7 +166,7 @@
* *
* @return bool * @return bool
*/ */
public function isHasSpoiler(): bool public function hasSpoiler(): bool
{ {
return $this->has_spoiler; return $this->has_spoiler;
} }
@ -175,23 +178,19 @@
*/ */
public function toArray(): array 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 [ return [
'type' => $this->type, 'type' => $this->type,
'media' => $this->media, 'media' => $this->media,
'thumb' => $this->thumb, 'thumb' => $this->thumb,
'caption' => $this->caption, 'caption' => $this->caption,
'parse_mode' => $this->parse_mode, '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, 'width' => $this->width,
'height' => $this->height, 'height' => $this->height,
'duration' => $this->duration, 'duration' => $this->duration,
@ -204,30 +203,24 @@
* *
* @param array $data * @param array $data
* @return ObjectTypeInterface * @return ObjectTypeInterface
* @noinspection DuplicatedCode
*/ */
public static function fromArray(array $data): ObjectTypeInterface 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 = new static();
$object->type = $data['type']; $object->type = $data['type'] ?? InputMediaType::Animation;
$object->media = $data['media']; $object->media = $data['media'] ?? null;
$object->thumb = $data['thumb']; $object->thumb = $data['thumb'] ?? null;
$object->caption = $data['caption']; $object->caption = $data['caption'] ?? null;
$object->parse_mode = $data['parse_mode']; $object->parse_mode = $data['parse_mode'] ?? null;
$object->caption_entities = $caption_entities; $object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
$object->width = $data['width']; {
$object->height = $data['height']; return MessageEntity::fromArray($item);
$object->duration = $data['duration']; }, $data['caption_entities']) : null;
$object->has_spoiler = $data['has_spoiler']; $object->width = $data['width'] ?? null;
$object->height = $data['height'] ?? null;
$object->duration = $data['duration'] ?? null;
$object->has_spoiler = $data['has_spoiler'] ?? false;
return $object; return $object;
} }
@ -237,6 +230,7 @@
* *
* @param InputMedia $inputMedia * @param InputMedia $inputMedia
* @return InputMediaAnimation * @return InputMediaAnimation
* @noinspection DuplicatedCode
*/ */
public static function fromInputMedia(InputMedia $inputMedia): InputMediaAnimation public static function fromInputMedia(InputMedia $inputMedia): InputMediaAnimation
{ {
@ -251,7 +245,7 @@
$object->width = $inputMedia->getWidth(); $object->width = $inputMedia->getWidth();
$object->height = $inputMedia->getHeight(); $object->height = $inputMedia->getHeight();
$object->duration = $inputMedia->getDuration(); $object->duration = $inputMedia->getDuration();
$object->has_spoiler = $inputMedia->isHasSpoiler(); $object->has_spoiler = $inputMedia->hasSpoiler();
return $object; return $object;
} }

View file

@ -160,23 +160,19 @@
*/ */
public function toArray(): array 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 [ return [
'type' => $this->type, 'type' => $this->type,
'media' => $this->media, 'media' => $this->media,
'thumb' => $this->thumb, 'thumb' => $this->thumb,
'caption' => $this->caption, 'caption' => $this->caption,
'parse_mode' => $this->parse_mode, '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, 'duration' => $this->duration,
'performer' => $this->performer, 'performer' => $this->performer,
'title' => $this->title 'title' => $this->title
@ -188,29 +184,24 @@
* *
* @param array $data * @param array $data
* @return ObjectTypeInterface * @return ObjectTypeInterface
* @noinspection DuplicatedCode
*/ */
public static function fromArray(array $data): ObjectTypeInterface 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 = new InputMediaAudio();
$object->type = $data['type']; $object->type = $data['type'] ?? null;
$object->media = $data['media']; $object->media = $data['media'] ?? null;
$object->thumb = $data['thumb']; $object->thumb = $data['thumb'] ?? null;
$object->caption = $data['caption']; $object->caption = $data['caption'] ?? null;
$object->parse_mode = $data['parse_mode']; $object->parse_mode = $data['parse_mode'] ?? null;
$object->caption_entities = $caption_entities; $object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
$object->duration = $data['duration']; {
$object->performer = $data['performer']; return MessageEntity::fromArray($item);
$object->title = $data['title']; }, $data['caption_entities']) : null;
$object->duration = $data['duration'] ?? null;
$object->performer = $data['performer'] ?? null;
$object->title = $data['title'] ?? null;
return $object; return $object;
} }

View file

@ -132,23 +132,19 @@
*/ */
public function toArray(): array 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 [ return [
'type' => $this->type, 'type' => $this->type,
'media' => $this->media, 'media' => $this->media,
'thumb' => $this->thumb, 'thumb' => $this->thumb,
'caption' => $this->caption, 'caption' => $this->caption,
'parse_mode' => $this->parse_mode, '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, 'disable_content_type_detection' => $this->disable_content_type_detection,
]; ];
} }
@ -158,27 +154,21 @@
* *
* @param array $data * @param array $data
* @return ObjectTypeInterface * @return ObjectTypeInterface
* @noinspection DuplicatedCode
*/ */
public static function fromArray(array $data): ObjectTypeInterface 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 = new InputMediaDocument();
$object->type = $data['type']; $object->type = $data['type'] ?? null;
$object->media = $data['media']; $object->media = $data['media'] ?? null;
$object->thumb = $data['thumb'] ?? null; $object->thumb = $data['thumb'] ?? null;
$object->caption = $data['caption'] ?? null; $object->caption = $data['caption'] ?? null;
$object->parse_mode = $data['parse_mode'] ?? null; $object->parse_mode = $data['parse_mode'] ?? null;
$object->caption_entities = $caption_entities; $object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
$object->disable_content_type_detection = $data['disable_content_type_detection']; {
return MessageEntity::fromArray($item);
}, $data['caption_entities']) : null;
$object->disable_content_type_detection = $data['disable_content_type_detection'] ?? false;
return $object; return $object;
} }
@ -192,6 +182,7 @@
public static function fromInputMedia(InputMedia $inputMedia): InputMediaDocument public static function fromInputMedia(InputMedia $inputMedia): InputMediaDocument
{ {
$object = new InputMediaDocument(); $object = new InputMediaDocument();
$object->type = $inputMedia->getType(); $object->type = $inputMedia->getType();
$object->media = $inputMedia->getMedia(); $object->media = $inputMedia->getMedia();
$object->thumb = $inputMedia->getThumb(); $object->thumb = $inputMedia->getThumb();

View file

@ -99,7 +99,7 @@
* *
* @return bool * @return bool
*/ */
public function isHasSpoiler(): bool public function hasSpoiler(): bool
{ {
return $this->has_spoiler; return $this->has_spoiler;
} }
@ -111,22 +111,18 @@
*/ */
public function toArray(): array 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 [ return [
'type' => $this->type, 'type' => $this->type,
'media' => $this->media, 'media' => $this->media,
'caption' => $this->caption, 'caption' => $this->caption,
'parse_mode' => $this->parse_mode, '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, 'has_spoiler' => $this->has_spoiler,
]; ];
} }
@ -141,20 +137,15 @@
{ {
$object = new self(); $object = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? null;
$object->media = $data['media']; $object->media = $data['media'] ?? null;
$object->caption = $data['caption']; $object->caption = $data['caption'] ?? null;
$object->parse_mode = $data['parse_mode']; $object->parse_mode = $data['parse_mode'] ?? null;
$object->has_spoiler = $data['has_spoiler']; $object->has_spoiler = $data['has_spoiler'] ?? null;
$object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
if (isset($data['caption_entities']))
{ {
$object->caption_entities = []; return MessageEntity::fromArray($item);
foreach ($data['caption_entities'] as $caption_entity) }, $data['caption_entities']) : null;
{
$object->caption_entities[] = MessageEntity::fromArray($caption_entity);
}
}
return $object; return $object;
} }
@ -173,16 +164,8 @@
$object->media = $inputMedia->getMedia(); $object->media = $inputMedia->getMedia();
$object->caption = $inputMedia->getCaption(); $object->caption = $inputMedia->getCaption();
$object->parse_mode = $inputMedia->getParseMode(); $object->parse_mode = $inputMedia->getParseMode();
$object->has_spoiler = $inputMedia->isHasSpoiler(); $object->has_spoiler = $inputMedia->hasSpoiler();
$object->caption_entities = $inputMedia->getCaptionEntities();
if ($inputMedia->getCaptionEntities())
{
$object->caption_entities = [];
foreach ($inputMedia->getCaptionEntities() as $caption_entity)
{
$object->caption_entities[] = MessageEntity::fromArray($caption_entity);
}
}
return $object; return $object;
} }

View file

@ -169,7 +169,7 @@
* *
* @return bool * @return bool
*/ */
public function isSupportsStreaming(): bool public function supportsStreaming(): bool
{ {
return $this->supports_streaming; return $this->supports_streaming;
} }
@ -179,7 +179,7 @@
* *
* @return bool * @return bool
*/ */
public function isHasSpoiler(): bool public function hasSpoiler(): bool
{ {
return $this->has_spoiler; return $this->has_spoiler;
} }
@ -191,23 +191,19 @@
*/ */
public function toArray(): array 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 [ return [
'type' => $this->type, 'type' => $this->type,
'media' => $this->media, 'media' => $this->media,
'thumb' => $this->thumb, 'thumb' => $this->thumb,
'caption' => $this->caption, 'caption' => $this->caption,
'parse_mode' => $this->parse_mode, '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, 'width' => $this->width,
'height' => $this->height, 'height' => $this->height,
'duration' => $this->duration, 'duration' => $this->duration,
@ -221,32 +217,26 @@
* *
* @param array $data * @param array $data
* @return ObjectTypeInterface * @return ObjectTypeInterface
* @noinspection DuplicatedCode
*/ */
public static function fromArray(array $data): ObjectTypeInterface 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 = new InputMediaVideo();
$object->type = $data['type']; $object->type = $data['type'] ?? null;
$object->media = $data['media']; $object->media = $data['media'] ?? null;
$object->thumb = @$data['thumb'] ?? null; $object->thumb = $data['thumb'] ?? null;
$object->caption = @$data['caption'] ?? null; $object->caption = $data['caption'] ?? null;
$object->parse_mode = @$data['parse_mode'] ?? null; $object->parse_mode = $data['parse_mode'] ?? null;
$object->caption_entities = $caption_entities; $object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
$object->width = @$data['width'] ?? null; {
$object->height = @$data['height'] ?? null; return MessageEntity::fromArray($item);
$object->duration = @$data['duration'] ?? null; }, $data['caption_entities']) : null;
$object->supports_streaming = @$data['supports_streaming'] ?? false; $object->width = $data['width'] ?? null;
$object->has_spoiler = @$data['has_spoiler'] ?? false; $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; return $object;
} }
@ -256,6 +246,7 @@
* *
* @param InputMedia $inputMedia * @param InputMedia $inputMedia
* @return InputMediaVideo * @return InputMediaVideo
* @noinspection DuplicatedCode
*/ */
public static function fromInputMedia(InputMedia $inputMedia): InputMediaVideo public static function fromInputMedia(InputMedia $inputMedia): InputMediaVideo
{ {
@ -271,7 +262,7 @@
$object->height = $inputMedia->getHeight(); $object->height = $inputMedia->getHeight();
$object->duration = $inputMedia->getDuration(); $object->duration = $inputMedia->getDuration();
$object->supports_streaming = $inputMedia->isSupportsStreaming(); $object->supports_streaming = $inputMedia->isSupportsStreaming();
$object->has_spoiler = $inputMedia->isHasSpoiler(); $object->has_spoiler = $inputMedia->hasSpoiler();
return $object; return $object;
} }

View file

@ -113,11 +113,11 @@
{ {
$object = new self(); $object = new self();
$object->title = $data['title']; $object->title = $data['title'] ?? null;
$object->description = $data['description']; $object->description = $data['description'] ?? null;
$object->start_parameter = $data['start_parameter']; $object->start_parameter = $data['start_parameter'] ?? null;
$object->currency = $data['currency']; $object->currency = $data['currency'] ?? null;
$object->total_amount = $data['total_amount']; $object->total_amount = $data['total_amount'] ?? null;
return $object; return $object;
} }

View file

@ -130,12 +130,12 @@
{ {
return [ return [
'text' => $this->text, 'text' => $this->text,
'request_user' => ($this->request_user instanceof KeyboardButtonRequestUser) ? $this->request_user->toArray() : null, 'request_user' => ($this->request_user instanceof ObjectTypeInterface) ? $this->request_user->toArray() : null,
'request_chat' => ($this->request_chat instanceof KeyboardButtonRequestChat) ? $this->request_chat->toArray() : null, 'request_chat' => ($this->request_chat instanceof ObjectTypeInterface) ? $this->request_chat->toArray() : null,
'request_contact' => $this->request_contact, 'request_contact' => $this->request_contact,
'request_location' => $this->request_location, 'request_location' => $this->request_location,
'request_poll' => ($this->request_poll instanceof KeyboardButtonPollType) ? $this->request_poll->toArray() : null, 'request_poll' => ($this->request_poll instanceof ObjectTypeInterface) ? $this->request_poll->toArray() : null,
'web_app' => ($this->web_app instanceof WebAppInfo) ? $this->web_app->toArray() : null, 'web_app' => ($this->web_app instanceof ObjectTypeInterface) ? $this->web_app->toArray() : null,
]; ];
} }
@ -149,11 +149,11 @@
{ {
$object = new self(); $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_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_chat = isset($data['request_chat']) ? KeyboardButtonRequestChat::fromArray($data['request_chat']) : null;
$object->request_contact = $data['request_contact']; $object->request_contact = $data['request_contact'] ?? null;
$object->request_location = $data['request_location']; $object->request_location = $data['request_location'] ?? null;
$object->request_poll = isset($data['request_poll']) ? KeyboardButtonPollType::fromArray($data['request_poll']) : 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; $object->web_app = isset($data['web_app']) ? WebAppInfo::fromArray($data['web_app']) : null;

View file

@ -1,5 +1,7 @@
<?php <?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects; namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
@ -44,7 +46,9 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->type = @$data['type'] ?? null;
$object->type = $data['type'] ?? null;
return $object; return $object;
} }
} }

View file

@ -65,7 +65,7 @@
* *
* @return bool * @return bool
*/ */
public function isChatIsChannel(): bool public function chatIsChannel(): bool
{ {
return $this->chat_is_channel; return $this->chat_is_channel;
} }
@ -76,7 +76,7 @@
* *
* @return bool * @return bool
*/ */
public function isChatIsForum(): bool public function chatIsForum(): bool
{ {
return $this->chat_is_forum; return $this->chat_is_forum;
} }
@ -87,7 +87,7 @@
* *
* @return bool * @return bool
*/ */
public function isChatHasUsername(): bool public function chatHasUsername(): bool
{ {
return $this->chat_has_username; return $this->chat_has_username;
} }
@ -97,7 +97,7 @@
* *
* @return bool * @return bool
*/ */
public function isChatIsCreated(): bool public function chatIsCreated(): bool
{ {
return $this->chat_is_created; return $this->chat_is_created;
} }
@ -132,7 +132,7 @@
* *
* @return bool * @return bool
*/ */
public function isBotIsMember(): bool public function botIsMember(): bool
{ {
return $this->bot_is_member; return $this->bot_is_member;
} }
@ -150,8 +150,8 @@
'chat_is_forum' => $this->chat_is_forum, 'chat_is_forum' => $this->chat_is_forum,
'chat_has_username' => $this->chat_has_username, 'chat_has_username' => $this->chat_has_username,
'chat_is_created' => $this->chat_is_created, 'chat_is_created' => $this->chat_is_created,
'user_administrator_rights' => ($this->user_administrator_rights instanceof ChatAdministratorRights) ? $this->user_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 ChatAdministratorRights) ? $this->bot_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, 'bot_is_member' => $this->bot_is_member,
]; ];
} }
@ -166,14 +166,14 @@
{ {
$object = new self(); $object = new self();
$object->request_id = $data['request_id']; $object->request_id = $data['request_id'] ?? null;
$object->chat_is_channel = $data['chat_is_channel']; $object->chat_is_channel = $data['chat_is_channel'] ?? false;
$object->chat_is_forum = $data['chat_is_forum']; $object->chat_is_forum = $data['chat_is_forum'] ?? false;
$object->chat_has_username = $data['chat_has_username']; $object->chat_has_username = $data['chat_has_username'] ?? false;
$object->chat_is_created = $data['chat_is_created']; $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->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_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; return $object;
} }

View file

@ -81,9 +81,9 @@
{ {
$object = new self(); $object = new self();
$object->request_id = $data['request_id']; $object->request_id = $data['request_id'] ?? null;
$object->user_is_bot = $data['user_is_bot']; $object->user_is_bot = $data['user_is_bot'] ?? false;
$object->user_is_premium = $data['user_is_premium']; $object->user_is_premium = $data['user_is_premium'] ?? false;
return $object; return $object;
} }

View file

@ -65,8 +65,8 @@
{ {
$object = new self(); $object = new self();
$object->label = $data['label']; $object->label = $data['label'] ?? null;
$object->amount = $data['amount']; $object->amount = $data['amount'] ?? null;
return $object; return $object;
} }

View file

@ -127,12 +127,12 @@
{ {
$object = new self(); $object = new self();
$object->longitude = $data['longitude']; $object->longitude = $data['longitude'] ?? null;
$object->latitude = $data['latitude']; $object->latitude = $data['latitude'] ?? null;
$object->horizontal_accuracy = $data['horizontal_accuracy']; $object->horizontal_accuracy = $data['horizontal_accuracy'] ?? null;
$object->live_period = $data['live_period']; $object->live_period = $data['live_period'] ?? null;
$object->heading = $data['heading']; $object->heading = $data['heading'] ?? null;
$object->proximity_alert_radius = $data['proximity_alert_radius']; $object->proximity_alert_radius = $data['proximity_alert_radius'] ?? null;
return $object; return $object;
} }

View file

@ -100,7 +100,7 @@
{ {
$object = new self(); $object = new self();
$object->url = $data['url']; $object->url = $data['url'] ?? null;
$object->forward_text = $data['forward_text'] ?? null; $object->forward_text = $data['forward_text'] ?? null;
$object->bot_username = $data['bot_username'] ?? null; $object->bot_username = $data['bot_username'] ?? null;
$object->request_write_access = $data['request_write_access'] ?? false; $object->request_write_access = $data['request_write_access'] ?? false;

View file

@ -96,10 +96,10 @@
{ {
$object = new self(); $object = new self();
$object->point = $data['point']; $object->point = $data['point'] ?? null;
$object->x_shift = $data['x_shift']; $object->x_shift = $data['x_shift'] ?? null;
$object->y_shift = $data['y_shift']; $object->y_shift = $data['y_shift'] ?? null;
$object->scale = $data['scale']; $object->scale = $data['scale'] ?? null;
return $object; return $object;
} }

View file

@ -64,7 +64,7 @@
return [ return [
'type' => $this->type, 'type' => $this->type,
'text' => $this->text, '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 = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? null;
$object->text = $data['text'] ?? null; $object->text = $data['text'] ?? null;
$object->web_app = ($data['web_app'] ?? null) ? WebAppInfo::fromArray($data['web_app']) : null; $object->web_app = ($data['web_app'] ?? null) ? WebAppInfo::fromArray($data['web_app']) : null;

View file

@ -46,7 +46,7 @@
{ {
$object = new self(); $object = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? null;
return $object; return $object;
} }
@ -60,7 +60,9 @@
public static function fromMenuButton(MenuButton $menuButton): MenuButtonCommands public static function fromMenuButton(MenuButton $menuButton): MenuButtonCommands
{ {
$object = new self(); $object = new self();
$object->type = $menuButton->getType(); $object->type = $menuButton->getType();
return $object; return $object;
} }
} }

View file

@ -46,7 +46,7 @@
{ {
$object = new self(); $object = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? null;
return $object; return $object;
} }

View file

@ -1,6 +1,8 @@
<?php /** @noinspection PhpMissingFieldTypeInspection */ <?php
namespace TgBotLib\Objects\MenuButton; /** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\MenuButton;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\MenuButton; use TgBotLib\Objects\MenuButton;
@ -65,7 +67,7 @@ namespace TgBotLib\Objects\MenuButton;
return [ return [
'type' => $this->type, 'type' => $this->type,
'text' => $this->text, '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 = new self();
$object->type = $data['type']; $object->type = $data['type'] ?? null;
$object->text = $data['text']; $object->text = $data['text'] ?? null;
$object->web_app = isset($data['web_app']) ? WebAppInfo::fromArray($data['web_app']) : null; $object->web_app = isset($data['web_app']) ? WebAppInfo::fromArray($data['web_app']) : null;
return $object; return $object;

View file

@ -496,7 +496,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsTopicMessage(): bool public function isTopicMessage(): bool
{ {
return $this->is_topic_message; return $this->is_topic_message;
} }
@ -548,7 +548,7 @@
* *
* @return bool * @return bool
*/ */
public function isHasProtectedContent(): bool public function hasProtectedContent(): bool
{ {
return $this->has_protected_content; return $this->has_protected_content;
} }
@ -703,7 +703,7 @@
* *
* @return bool * @return bool
*/ */
public function isHasMediaSpoiler(): bool public function hasMediaSpoiler(): bool
{ {
return $this->has_media_spoiler; return $this->has_media_spoiler;
} }
@ -1113,125 +1113,107 @@
*/ */
public function toArray(): array 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 [ return [
'message_id' => $this->message_id, 'message_id' => $this->message_id,
'message_thread_id' => $this->message_thread_id, 'message_thread_id' => $this->message_thread_id,
'from' => ($this->from instanceof User) ? $this->from->toArray() : null, 'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : null,
'sender_chat' => ($this->sender_chat instanceof Chat) ? $this->sender_chat->toArray() : null, 'sender_chat' => ($this->sender_chat instanceof ObjectTypeInterface) ? $this->sender_chat->toArray() : null,
'date' => $this->date, 'date' => $this->date,
'chat' => ($this->chat instanceof Chat) ? $this->chat->toArray() : null, 'chat' => ($this->chat instanceof ObjectTypeInterface) ? $this->chat->toArray() : null,
'forward_from' => ($this->forward_from instanceof User) ? $this->forward_from->toArray() : null, 'forward_from' => ($this->forward_from instanceof ObjectTypeInterface) ? $this->forward_from->toArray() : null,
'forward_from_chat' => ($this->forward_from_chat instanceof Chat) ? $this->forward_from_chat->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_from_message_id' => $this->forward_from_message_id,
'forward_signature' => $this->forward_signature, 'forward_signature' => $this->forward_signature,
'forward_sender_name' => $this->forward_sender_name, 'forward_sender_name' => $this->forward_sender_name,
'forward_date' => $this->forward_date, 'forward_date' => $this->forward_date,
'is_topic_message' => $this->is_topic_message, 'is_topic_message' => $this->is_topic_message,
'is_automatic_forward' => $this->is_automatic_forward, 'is_automatic_forward' => $this->is_automatic_forward,
'reply_to_message' => ($this->reply_to_message instanceof Message) ? $this->reply_to_message->toArray() : null, 'reply_to_message' => ($this->reply_to_message instanceof ObjectTypeInterface) ? $this->reply_to_message->toArray() : null,
'via_bot' => ($this->via_bot instanceof User) ? $this->via_bot->toArray() : null, 'via_bot' => ($this->via_bot instanceof ObjectTypeInterface) ? $this->via_bot->toArray() : null,
'edit_date' => $this->edit_date, 'edit_date' => $this->edit_date,
'has_protected_content' => $this->has_protected_content, 'has_protected_content' => $this->has_protected_content,
'media_group_id' => $this->media_group_id, 'media_group_id' => $this->media_group_id,
'author_signature' => $this->author_signature, 'author_signature' => $this->author_signature,
'text' => $this->text, 'text' => $this->text,
'entities' => $entities, 'entities' => is_array($this->entities) ? array_map(function ($entity) {
'animation' => ($this->animation instanceof Animation) ? $this->animation->toArray() : null, if ($entity instanceof ObjectTypeInterface)
'audio' => ($this->audio instanceof Audio) ? $this->audio->toArray() : null, {
'document' => ($this->document instanceof Document) ? $this->document->toArray() : null, return $entity->toArray();
'photo' => $photo, }
'sticker' => ($this->sticker instanceof Sticker) ? $this->sticker->toArray() : null, return $entity;
'video' => ($this->video instanceof Video) ? $this->video->toArray() : null, }, $this->entities) : null,
'video_note' => ($this->video_note instanceof VideoNote) ? $this->video_note->toArray() : null, 'animation' => ($this->animation instanceof ObjectTypeInterface) ? $this->animation->toArray() : null,
'voice' => ($this->voice instanceof Voice) ? $this->voice->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' => $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, 'has_media_spoiler' => $this->has_media_spoiler,
'contact' => ($this->contact instanceof Contact) ? $this->contact->toArray() : null, 'contact' => ($this->contact instanceof ObjectTypeInterface) ? $this->contact->toArray() : null,
'dice' => ($this->dice instanceof Dice) ? $this->dice->toArray() : null, 'dice' => ($this->dice instanceof ObjectTypeInterface) ? $this->dice->toArray() : null,
'game' => ($this->game instanceof Game) ? $this->game->toArray() : null, 'game' => ($this->game instanceof ObjectTypeInterface) ? $this->game->toArray() : null,
'poll' => ($this->poll instanceof Poll) ? $this->poll->toArray() : null, 'poll' => ($this->poll instanceof ObjectTypeInterface) ? $this->poll->toArray() : null,
'venue' => ($this->venue instanceof Venue) ? $this->venue->toArray() : null, 'venue' => ($this->venue instanceof ObjectTypeInterface) ? $this->venue->toArray() : null,
'location' => ($this->location instanceof Location) ? $this->location->toArray() : null, 'location' => ($this->location instanceof ObjectTypeInterface) ? $this->location->toArray() : null,
'new_chat_members' => $new_chat_members, 'new_chat_members' => is_array($this->new_chat_members) ? array_map(function ($new_chat_member) {
'left_chat_member' => ($this->left_chat_member instanceof User) ? $this->left_chat_member->toArray() : null, 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_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, 'delete_chat_photo' => $this->delete_chat_photo,
'group_chat_created' => $this->group_chat_created, 'group_chat_created' => $this->group_chat_created,
'supergroup_chat_created' => $this->supergroup_chat_created, 'supergroup_chat_created' => $this->supergroup_chat_created,
'channel_chat_created' => $this->channel_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, 'migrate_to_chat_id' => $this->migrate_to_chat_id,
'pinned_message' => ($this->pinned_message instanceof Message) ? $this->pinned_message->toArray() : null, 'pinned_message' => ($this->pinned_message instanceof ObjectTypeInterface) ? $this->pinned_message->toArray() : null,
'invoice' => ($this->invoice instanceof Invoice) ? $this->invoice->toArray() : null, 'invoice' => ($this->invoice instanceof ObjectTypeInterface) ? $this->invoice->toArray() : null,
'successful_payment' => ($this->successful_payment instanceof SuccessfulPayment) ? $this->successful_payment->toArray() : null, 'successful_payment' => ($this->successful_payment instanceof ObjectTypeInterface) ? $this->successful_payment->toArray() : null,
'user_shared' => ($this->user_shared instanceof UserShared) ? $this->user_shared->toArray() : null, 'user_shared' => ($this->user_shared instanceof ObjectTypeInterface) ? $this->user_shared->toArray() : null,
'chat_shared' => ($this->chat_shared instanceof ChatShared) ? $this->chat_shared->toArray() : null, 'chat_shared' => ($this->chat_shared instanceof ObjectTypeInterface) ? $this->chat_shared->toArray() : null,
'connected_website' => $this->connected_website, 'connected_website' => $this->connected_website,
'write_access_allowed' => ($this->write_access_allowed instanceof WriteAccessAllowed) ? $this->write_access_allowed->toArray() : null, 'write_access_allowed' => ($this->write_access_allowed instanceof ObjectTypeInterface) ? $this->write_access_allowed->toArray() : null,
'passport_data' => ($this->passport_data instanceof PassportData) ? $this->passport_data->toArray() : null, 'passport_data' => ($this->passport_data instanceof ObjectTypeInterface) ? $this->passport_data->toArray() : null,
'proximity_alert_triggered' => ($this->proximity_alert_triggered instanceof ProximityAlertTriggered) ? $this->proximity_alert_triggered->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 ForumTopicCreated) ? $this->forum_topic_created->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 ForumTopicEdited) ? $this->forum_topic_edited->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 ForumTopicClosed) ? $this->forum_topic_closed->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 ForumTopicReopened) ? $this->forum_topic_reopened->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 GeneralForumTopicHidden) ? $this->general_forum_topic_hidden->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 GeneralForumTopicUnhidden) ? $this->general_forum_topic_unhidden->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 VideoChatScheduled) ? $this->video_chat_scheduled->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 VideoChatStarted) ? $this->video_chat_started->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 VideoChatEnded) ? $this->video_chat_ended->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 VideoChatParticipantsInvited) ? $this->video_chat_participants_invited->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 WebAppData) ? $this->web_app_data->toArray() : null, 'web_app_data' => ($this->web_app_data instanceof ObjectTypeInterface) ? $this->web_app_data->toArray() : null,
'reply_markup' => ($this->reply_markup instanceof InlineKeyboardMarkup) ? $this->reply_markup->toArray() : null, 'reply_markup' => ($this->reply_markup instanceof ObjectTypeInterface) ? $this->reply_markup->toArray() : null,
]; ];
} }
@ -1245,120 +1227,88 @@
{ {
$object = new self(); $object = new self();
$object->message_id = @$data['message_id'] ?? null; $object->message_id = $data['message_id'] ?? null;
$object->message_thread_id = @$data['message_thread_id'] ?? null; $object->message_thread_id = $data['message_thread_id'] ?? null;
$object->from = (@$data['from'] !== null) ? User::fromArray($data['from']) : 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->sender_chat = ($data['sender_chat'] !== null) ? Chat::fromArray($data['sender_chat']) : null;
$object->date = @$data['date'] ?? null; $object->date = $data['date'] ?? null;
$object->chat = (@$data['chat'] !== null) ? Chat::fromArray($data['chat']) : 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 = ($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_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_from_message_id = $data['forward_from_message_id'] ?? null;
$object->forward_signature = @$data['forward_signature'] ?? null; $object->forward_signature = $data['forward_signature'] ?? null;
$object->forward_sender_name = @$data['forward_sender_name'] ?? null; $object->forward_sender_name = $data['forward_sender_name'] ?? null;
$object->forward_date = @$data['forward_date'] ?? null; $object->forward_date = $data['forward_date'] ?? null;
$object->is_topic_message = @$data['is_topic_message'] ?? null; $object->is_topic_message = $data['is_topic_message'] ?? null;
$object->is_automatic_forward = @$data['is_automatic_forward'] ?? 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->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->via_bot = ($data['via_bot'] !== null) ? User::fromArray($data['via_bot']) : null;
$object->edit_date = @$data['edit_date'] ?? null; $object->edit_date = $data['edit_date'] ?? null;
$object->has_protected_content = @$data['has_protected_content'] ?? null; $object->has_protected_content = $data['has_protected_content'] ?? null;
$object->media_group_id = @$data['media_group_id'] ?? null; $object->media_group_id = $data['media_group_id'] ?? null;
$object->author_signature = @$data['author_signature'] ?? null; $object->author_signature = $data['author_signature'] ?? null;
$object->text = @$data['text'] ?? null; $object->text = $data['text'] ?? null;
$object->entities = isset($data['entities']) && is_array($data['entities']) ? array_map(function ($item) {
if (isset($data['entities']) && is_array($data['entities'])) { return MessageEntity::fromArray($item);
$object->entities = []; }, $data['entities']) : null;
foreach ($data['entities'] as $item) { $object->animation = ($data['animation'] !== null) ? Animation::fromArray($data['animation']) : null;
$object->entities[] = MessageEntity::fromArray($item); $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->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->photo = []; return PhotoSize::fromArray($item);
foreach ($data['photo'] as $item) }, $data['photo']) : null;
{ $object->sticker = ($data['sticker'] !== null) ? Sticker::fromArray($data['sticker']) : null;
$object->photo[] = PhotoSize::fromArray($item); $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->sticker = (@$data['sticker'] !== null) ? Sticker::fromArray($data['sticker']) : null; $object->caption_entities = isset($data['caption_entities']) && is_array($data['caption_entities']) ? array_map(function ($item) {
$object->video = (@$data['video'] !== null) ? Video::fromArray($data['video']) : null; return MessageEntity::fromArray($item);
$object->video_note = (@$data['video_note'] !== null) ? VideoNote::fromArray($data['video_note']) : null; }, $data['caption_entities']) : null;
$object->voice = (@$data['voice'] !== null) ? Voice::fromArray($data['voice']) : null; $object->has_media_spoiler = $data['has_media_spoiler'] ?? null;
$object->caption = @$data['caption'] ?? null; $object->contact = ($data['contact'] !== null) ? Contact::fromArray($data['contact']) : null;
$object->dice = ($data['dice'] !== null) ? Dice::fromArray($data['dice']) : null;
if (isset($data['caption_entities']) && is_array($data['caption_entities'])) $object->game = ($data['game'] !== null) ? Game::fromArray($data['game']) : null;
{ $object->poll = ($data['poll'] !== null) ? Poll::fromArray($data['poll']) : null;
$object->caption_entities = []; $object->venue = ($data['venue'] !== null) ? Venue::fromArray($data['venue']) : null;
foreach ($data['caption_entities'] as $item) $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) {
$object->caption_entities[] = MessageEntity::fromArray($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->has_media_spoiler = @$data['has_media_spoiler'] ?? null; $object->new_chat_photo = isset($data['new_chat_photo']) && is_array($data['new_chat_photo']) ? array_map(function ($item) {
$object->contact = (@$data['contact'] !== null) ? Contact::fromArray($data['contact']) : null; return PhotoSize::fromArray($item);
$object->dice = (@$data['dice'] !== null) ? Dice::fromArray($data['dice']) : null; }, $data['new_chat_photo']) : null;
$object->game = (@$data['game'] !== null) ? Game::fromArray($data['game']) : null; $object->delete_chat_photo = $data['delete_chat_photo'] ?? null;
$object->poll = (@$data['poll'] !== null) ? Poll::fromArray($data['poll']) : null; $object->group_chat_created = $data['group_chat_created'] ?? null;
$object->venue = (@$data['venue'] !== null) ? Venue::fromArray($data['venue']) : null; $object->supergroup_chat_created = $data['supergroup_chat_created'] ?? null;
$object->location = (@$data['location'] !== null) ? Location::fromArray($data['location']) : 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;
if (isset($data['new_chat_members']) && is_array($data['new_chat_members'])) $object->migrate_to_chat_id = $data['migrate_to_chat_id'] ?? null;
{ $object->migrate_from_chat_id = $data['migrate_from_chat_id'] ?? null;
$object->new_chat_members = []; $object->pinned_message = ($data['pinned_message'] !== null) ? self::fromArray($data['pinned_message']) : null;
foreach ($data['new_chat_members'] as $item) $object->invoice = ($data['invoice'] !== null) ? Invoice::fromArray($data['invoice']) : null;
{ $object->successful_payment = ($data['successful_payment'] !== null) ? SuccessfulPayment::fromArray($data['successful_payment']) : null;
$object->new_chat_members[] = User::fromArray($item); $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->left_chat_member = (@$data['left_chat_member'] !== null) ? User::fromArray($data['left_chat_member']) : null; $object->passport_data = ($data['passport_data'] !== null) ? PassportData::fromArray($data['passport_data']) : null;
$object->new_chat_title = @$data['new_chat_title'] ?? 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;
if (isset($data['new_chat_photo']) && is_array($data['new_chat_photo'])) $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->new_chat_photo = []; $object->forum_topic_reopened = ($data['forum_topic_reopened'] !== null) ? ForumTopicReopened::fromArray($data['forum_topic_reopened']) : null;
foreach ($data['new_chat_photo'] as $item) $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->new_chat_photo[] = PhotoSize::fromArray($item); $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->delete_chat_photo = @$data['delete_chat_photo'] ?? null; $object->web_app_data = ($data['web_app_data'] !== null) ? WebAppData::fromArray($data['web_app_data']) : null;
$object->group_chat_created = @$data['group_chat_created'] ?? null; $object->reply_markup = ($data['reply_markup'] !== null) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : 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; return $object;
} }

View file

@ -42,6 +42,7 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->message_auto_delete_time = $data['message_auto_delete_time']; $object->message_auto_delete_time = $data['message_auto_delete_time'];
return $object; return $object;

View file

@ -128,13 +128,13 @@
public function toArray(): array public function toArray(): array
{ {
return [ return [
'type' => $this->type ?? null, 'type' => $this->type,
'offset' => $this->offset ?? null, 'offset' => $this->offset,
'length' => $this->length ?? null, 'length' => $this->length,
'url' => $this->url ?? null, 'url' => $this->url,
'user' => ($this->user instanceof User) ? $this->user->toArray() : null, 'user' => ($this->user instanceof ObjectTypeInterface) ? $this->user->toArray() : null,
'language' => $this->language ?? null, 'language' => $this->language,
'custom_emoji_id' => $this->custom_emoji_id ?? null, 'custom_emoji_id' => $this->custom_emoji_id
]; ];
} }

View file

@ -46,9 +46,13 @@
public function toArray(): array public function toArray(): array
{ {
return [ 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), }, $this->data),
'credentials' => $this->credentials->toArray(), 'credentials' => $this->credentials->toArray(),
]; ];

View file

@ -94,10 +94,10 @@
{ {
$object = new self(); $object = new self();
$object->file_id = $data['file_id']; $object->file_id = $data['file_id'] ?? null;
$object->file_unique_id = $data['file_unique_id']; $object->file_unique_id = $data['file_unique_id'] ?? null;
$object->file_size = $data['file_size']; $object->file_size = $data['file_size'] ?? null;
$object->file_date = $data['file_date']; $object->file_date = $data['file_date'] ?? null;
return $object; return $object;
} }

View file

@ -1,5 +1,7 @@
<?php <?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects; namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
@ -104,15 +106,16 @@
* *
* @param array $data * @param array $data
* @return ObjectTypeInterface * @return ObjectTypeInterface
* @noinspection DuplicatedCode
*/ */
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->file_id = $data['file_id']; $object->file_id = $data['file_id'] ?? null;
$object->file_unique_id = $data['file_unique_id']; $object->file_unique_id = $data['file_unique_id'] ?? null;
$object->width = $data['width']; $object->width = $data['width'] ?? null;
$object->height = $data['height']; $object->height = $data['height'] ?? null;
$object->file_size = $data['file_size'] ?? null; $object->file_size = $data['file_size'] ?? null;
return $object; return $object;

View file

@ -62,7 +62,7 @@
{ {
return [ return [
'poll_id' => $this->poll_id, 'poll_id' => $this->poll_id,
'user' => $this->user->toArray(), 'user' => ($this->user instanceof ObjectTypeInterface) ? $this->user->toArray() : null,
'option_ids' => $this->option_ids, 'option_ids' => $this->option_ids,
]; ];
} }
@ -77,8 +77,8 @@
{ {
$object = new self(); $object = new self();
$object->poll_id = $data['poll_id']; $object->poll_id = $data['poll_id'] ?? null;
$object->user = User::fromArray($data['user']); $object->user = isset($data['user']) && is_array($data['user']) ? User::fromArray($data['user']) : null;
$object->option_ids = $data['option_ids']; $object->option_ids = $data['option_ids'];
return $object; return $object;

View file

@ -61,8 +61,8 @@
{ {
$object = new self(); $object = new self();
$object->text = $data['text']; $object->text = $data['text'] ?? null;
$object->voter_count = $data['voter_count']; $object->voter_count = $data['voter_count'] ?? null;
return $object; return $object;
} }

View file

@ -125,12 +125,12 @@
{ {
return [ return [
'id' => $this->id, 'id' => $this->id,
'from' => ($this->from instanceof User) ? $this->from->toArray() : null, 'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : null,
'currency' => $this->currency, 'currency' => $this->currency,
'total_amount' => $this->total_amount, 'total_amount' => $this->total_amount,
'invoice_payload' => $this->invoice_payload, 'invoice_payload' => $this->invoice_payload,
'shipping_option_id' => $this->shipping_option_id, '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 public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->id = $data['id']; $object->id = $data['id'] ?? null;
$object->from = User::fromArray($data['from']); $object->from = isset($data['from']) && is_array($data['from']) ? User::fromArray($data['from']) : null;
$object->currency = $data['currency']; $object->currency = $data['currency'] ?? null;
$object->total_amount = $data['total_amount']; $object->total_amount = $data['total_amount'] ?? null;
$object->invoice_payload = $data['invoice_payload']; $object->invoice_payload = $data['invoice_payload'] ?? null;
$object->shipping_option_id = $data['shipping_option_id'] ?? 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; return $object;
} }
} }

View file

@ -1,5 +1,7 @@
<?php <?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects; namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
@ -74,8 +76,8 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->traveler = User::fromArray($data['traveler']); $object->traveler = isset($data['traveler']) && is_array($data['traveler']) ? User::fromArray($data['traveler']) : $data['traveler'];
$object->watcher = User::fromArray($data['watcher']); $object->watcher = isset($data['watcher']) && is_array($data['watcher']) ? User::fromArray($data['watcher']) : $data['watcher'];
$object->distance = $data['distance']; $object->distance = $data['distance'];
return $object; return $object;

View file

@ -1,5 +1,7 @@
<?php <?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects; namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
@ -133,12 +135,12 @@
{ {
$object = new self(); $object = new self();
$object->keyboard = $data['keyboard']; $object->keyboard = $data['keyboard'] ?? null;
$object->is_persistent = $data['is_persistent']; $object->is_persistent = $data['is_persistent'] ?? null;
$object->resize_keyboard = $data['resize_keyboard']; $object->resize_keyboard = $data['resize_keyboard'] ?? null;
$object->one_time_keyboard = $data['one_time_keyboard']; $object->one_time_keyboard = $data['one_time_keyboard'] ?? null;
$object->input_field_placeholder = $data['input_field_placeholder']; $object->input_field_placeholder = $data['input_field_placeholder'] ?? null;
$object->selective = $data['selective']; $object->selective = $data['selective'] ?? null;
return $object; return $object;
} }

View file

@ -66,8 +66,8 @@
public static function fromArray(array $data): ObjectTypeInterface public static function fromArray(array $data): ObjectTypeInterface
{ {
$object = new self(); $object = new self();
$object->remove_keyboard = @$data['remove_keyboard'] ?? false; $object->remove_keyboard = $data['remove_keyboard'] ?? false;
$object->selective = @$data['selective'] ?? false; $object->selective = $data['selective'] ?? false;
return $object; return $object;
} }
} }

View file

@ -93,10 +93,10 @@
{ {
$object = new self(); $object = new self();
$object->id = $data['id']; $object->id = $data['id'] ?? null;
$object->from = User::fromArray($data['from']); $object->from = isset($data['from']) && is_array($data['from']) ? User::fromArray($data['from']) : $data['from'];
$object->invoice_payload = $data['invoice_payload']; $object->invoice_payload = $data['invoice_payload'] ?? null;
$object->shipping_address = ShippingAddress::fromArray($data['shipping_address']); $object->shipping_address = isset($data['shipping_address']) && is_array($data['shipping_address']) ? ShippingAddress::fromArray($data['shipping_address']) : $data['shipping_address'];
return $object; return $object;
} }

View file

@ -237,11 +237,11 @@
'height' => $this->height, 'height' => $this->height,
'is_animated' => $this->is_animated, 'is_animated' => $this->is_animated,
'is_video' => $this->is_video, '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, 'emoji' => $this->emoji,
'set_name' => $this->set_name, 'set_name' => $this->set_name,
'premium_animation' => ($this->premium_animation instanceof File) ? $this->premium_animation->toArray() : null, 'premium_animation' => ($this->premium_animation instanceof ObjectTypeInterface) ? $this->premium_animation->toArray() : $this->thumb,
'mask_position' => ($this->mask_position instanceof MaskPosition) ? $this->mask_position->toArray() : null, 'mask_position' => ($this->mask_position instanceof ObjectTypeInterface) ? $this->mask_position->toArray() : $this->mask_position,
'custom_emoji_id' => $this->custom_emoji_id, 'custom_emoji_id' => $this->custom_emoji_id,
'file_size' => $this->file_size, 'file_size' => $this->file_size,
]; ];

View file

@ -129,7 +129,7 @@
'total_amount' => $this->total_amount, 'total_amount' => $this->total_amount,
'invoice_payload' => $this->invoice_payload, 'invoice_payload' => $this->invoice_payload,
'shipping_option_id' => $this->shipping_option_id, '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, 'telegram_payment_charge_id' => $this->telegram_payment_charge_id,
'provider_payment_charge_id' => $this->provider_payment_charge_id, 'provider_payment_charge_id' => $this->provider_payment_charge_id,
]; ];
@ -145,13 +145,13 @@
{ {
$object = new self(); $object = new self();
$object->currency = $data['currency']; $object->currency = $data['currency'] ?? null;
$object->total_amount = $data['total_amount']; $object->total_amount = $data['total_amount'] ?? null;
$object->invoice_payload = $data['invoice_payload']; $object->invoice_payload = $data['invoice_payload'] ?? null;
$object->shipping_option_id = $data['shipping_option_id'] ?? null; $object->shipping_option_id = $data['shipping_option_id'] ?? null;
$object->order_info = isset($data['order_info']) ? OrderInfo::fromArray($data['order_info']) : 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->telegram_payment_charge_id = $data['telegram_payment_charge_id'] ?? null;
$object->provider_payment_charge_id = $data['provider_payment_charge_id']; $object->provider_payment_charge_id = $data['provider_payment_charge_id'] ?? null;
return $object; return $object;
} }

View file

@ -80,7 +80,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsBot(): bool public function isBot(): bool
{ {
return $this->is_bot; return $this->is_bot;
} }
@ -131,7 +131,7 @@
* *
* @return bool * @return bool
*/ */
public function isIsPremium(): bool public function isPremium(): bool
{ {
return $this->is_premium; return $this->is_premium;
} }
@ -152,7 +152,7 @@
* @see https://core.telegram.org/bots/api#getme * @see https://core.telegram.org/bots/api#getme
* @return bool * @return bool
*/ */
public function isCanJoinGroups(): bool public function canJoinGroups(): bool
{ {
return $this->can_join_groups; return $this->can_join_groups;
} }
@ -164,7 +164,7 @@
* @see https://core.telegram.org/bots#privacy-mode * @see https://core.telegram.org/bots#privacy-mode
* @return bool * @return bool
*/ */
public function isCanReadAllGroupMessages(): bool public function canReadAllGroupMessages(): bool
{ {
return $this->can_read_all_group_messages; return $this->can_read_all_group_messages;
} }
@ -174,7 +174,7 @@
* *
* @return bool * @return bool
*/ */
public function isSupportsInlineQueries(): bool public function supportsInlineQueries(): bool
{ {
return $this->supports_inline_queries; return $this->supports_inline_queries;
} }
@ -211,17 +211,17 @@
{ {
$object = new self(); $object = new self();
$object->id = @$data['id']; $object->id = $data['id'] ?? null;
$object->is_bot = @$data['is_bot']; $object->is_bot = $data['is_bot'] ?? false;
$object->first_name = @$data['first_name']; $object->first_name = $data['first_name'] ?? null;
$object->last_name = @$data['last_name'] ?? null; $object->last_name = $data['last_name'] ?? null;
$object->username = @$data['username'] ?? null; $object->username = $data['username'] ?? null;
$object->language_code = @$data['language_code'] ?? null; $object->language_code = $data['language_code'] ?? null;
$object->is_premium = @$data['is_premium'] ?? false; $object->is_premium = $data['is_premium'] ?? false;
$object->added_to_attachment_menu = @$data['added_to_attachment_menu'] ?? false; $object->added_to_attachment_menu = $data['added_to_attachment_menu'] ?? false;
$object->can_join_groups = @$data['can_join_groups'] ?? false; $object->can_join_groups = $data['can_join_groups'] ?? false;
$object->can_read_all_group_messages = @$data['can_read_all_group_messages'] ?? false; $object->can_read_all_group_messages = $data['can_read_all_group_messages'] ?? false;
$object->supports_inline_queries = @$data['supports_inline_queries'] ?? false; $object->supports_inline_queries = $data['supports_inline_queries'] ?? false;
return $object; return $object;
} }

View file

@ -121,7 +121,7 @@
public function toArray(): array public function toArray(): array
{ {
return [ return [
'location' => ($this->location instanceof Location) ? $this->location->toArray() : $this->location, 'location' => ($this->location instanceof ObjectTypeInterface) ? $this->location->toArray() : $this->location,
'title' => $this->title, 'title' => $this->title,
'address' => $this->address, 'address' => $this->address,
'foursquare_id' => $this->foursquare_id, 'foursquare_id' => $this->foursquare_id,
@ -142,12 +142,12 @@
$object = new self(); $object = new self();
$object->location = isset($data['location']) ? Location::fromArray($data['location']) : null; $object->location = isset($data['location']) ? Location::fromArray($data['location']) : null;
$object->title = @$data['title']; $object->title = $data['title'];
$object->address = @$data['address']; $object->address = $data['address'];
$object->foursquare_id = @$data['foursquare_id'] ?? null; $object->foursquare_id = $data['foursquare_id'] ?? null;
$object->foursquare_type = @$data['foursquare_type'] ?? null; $object->foursquare_type = $data['foursquare_type'] ?? null;
$object->google_place_id = @$data['google_place_id'] ?? null; $object->google_place_id = $data['google_place_id'] ?? null;
$object->google_place_type = @$data['google_place_type'] ?? null; $object->google_place_type = $data['google_place_type'] ?? null;
return $object; return $object;
} }

View file

@ -157,7 +157,7 @@
'width' => $this->width, 'width' => $this->width,
'height' => $this->height, 'height' => $this->height,
'duration' => $this->duration, '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, 'file_name' => $this->file_name ?? null,
'mime_type' => $this->mime_type ?? null, 'mime_type' => $this->mime_type ?? null,
'file_size' => $this->file_size ?? null, 'file_size' => $this->file_size ?? null,

View file

@ -109,7 +109,7 @@
'file_unique_id' => $this->file_unique_id, 'file_unique_id' => $this->file_unique_id,
'length' => $this->length, 'length' => $this->length,
'duration' => $this->duration, '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, 'file_size' => $this->file_size,
]; ];
} }
@ -124,12 +124,12 @@
{ {
$object = new self(); $object = new self();
$object->file_id = @$data['file_id']; $object->file_id = $data['file_id'];
$object->file_unique_id = @$data['file_unique_id']; $object->file_unique_id = $data['file_unique_id'];
$object->length = @$data['length']; $object->length = $data['length'];
$object->duration = @$data['duration']; $object->duration = $data['duration'];
$object->thumb = (isset($data['thumb'])) ? PhotoSize::fromArray($data['thumb']) : null; $object->thumb = (isset($data['thumb'])) ? PhotoSize::fromArray($data['thumb']) : null;
$object->file_size = @$data['file_size']; $object->file_size = $data['file_size'];
return $object; return $object;
} }

View file

@ -111,11 +111,11 @@
{ {
$object = new self(); $object = new self();
$object->file_id = @$data['file_id']; $object->file_id = $data['file_id'];
$object->file_unique_id = @$data['file_unique_id']; $object->file_unique_id = $data['file_unique_id'];
$object->duration = @$data['duration']; $object->duration = $data['duration'];
$object->mime_type = @$data['mime_type'] ?? null; $object->mime_type = $data['mime_type'] ?? null;
$object->file_size = @$data['file_size'] ?? null; $object->file_size = $data['file_size'] ?? null;
return $object; return $object;
} }

View file

@ -60,8 +60,8 @@
{ {
$object = new self(); $object = new self();
$object->data = @$data['data'] ?: ''; $object->data = $data['data'] ?: '';
$object->button_text = @$data['button_text'] ?: ''; $object->button_text = $data['button_text'] ?: '';
return $object; return $object;
} }