From 89a00f11b7223b7d145a90cfc49c5693b6aca596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Tue, 11 Jun 2019 20:38:19 +0200 Subject: [PATCH 1/3] Return an empty array for Entity properties with no items, instead of `null` --- CHANGELOG.md | 2 ++ src/DB.php | 12 ++++---- src/Entities/Games/Game.php | 12 +++----- src/Entities/Message.php | 30 +++++++------------ src/Entities/Poll.php | 6 ++-- src/Entities/StickerSet.php | 6 ++-- .../EncryptedPassportElement.php | 12 +++----- .../TelegramPassport/PassportData.php | 6 ++-- 8 files changed, 32 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 976b2aa86..bc3d5a05e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ### Added ### Changed - Use PSR-12 for code style. +- [:exclamation:][unreleased-bc] Return an empty array for Entity properties with no items, instead of `null`. ### Deprecated ### Removed ### Fixed @@ -264,6 +265,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c - Move `hideKeyboard` to `removeKeyboard`. [unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/unreleased.sql +[unreleased-bc]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#unreleased [0.57.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.56.0-0.57.0.sql [0.55.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.54.1-0.55.0.sql [0.55.0-bc-move-animation-out-of-games-namespace]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#move-animation-out-of-games-namespace diff --git a/src/DB.php b/src/DB.php index e4108d21b..a00b75e77 100644 --- a/src/DB.php +++ b/src/DB.php @@ -844,7 +844,7 @@ public static function insertPollRequest(Poll $poll) $sth->bindValue(':id', $poll->getId()); $sth->bindValue(':question', $poll->getQuestion()); - $sth->bindValue(':options', self::entitiesArrayToJson($poll->getOptions())); + $sth->bindValue(':options', self::entitiesArrayToJson($poll->getOptions() ?: null)); $sth->bindValue(':is_closed', $poll->getIsClosed()); $sth->bindValue(':created_at', self::getTimestamp()); @@ -976,13 +976,13 @@ public static function insertMessageRequest(Message $message) $sth->bindValue(':media_group_id', $message->getMediaGroupId()); $sth->bindValue(':author_signature', $message->getAuthorSignature()); $sth->bindValue(':text', $message->getText()); - $sth->bindValue(':entities', self::entitiesArrayToJson($message->getEntities())); - $sth->bindValue(':caption_entities', self::entitiesArrayToJson($message->getCaptionEntities())); + $sth->bindValue(':entities', self::entitiesArrayToJson($message->getEntities() ?: null)); + $sth->bindValue(':caption_entities', self::entitiesArrayToJson($message->getCaptionEntities() ?: null)); $sth->bindValue(':audio', $message->getAudio()); $sth->bindValue(':document', $message->getDocument()); $sth->bindValue(':animation', $message->getAnimation()); $sth->bindValue(':game', $message->getGame()); - $sth->bindValue(':photo', self::entitiesArrayToJson($message->getPhoto())); + $sth->bindValue(':photo', self::entitiesArrayToJson($message->getPhoto() ?: null)); $sth->bindValue(':sticker', $message->getSticker()); $sth->bindValue(':video', $message->getVideo()); $sth->bindValue(':voice', $message->getVoice()); @@ -995,7 +995,7 @@ public static function insertMessageRequest(Message $message) $sth->bindValue(':new_chat_members', $new_chat_members_ids); $sth->bindValue(':left_chat_member', $left_chat_member_id); $sth->bindValue(':new_chat_title', $message->getNewChatTitle()); - $sth->bindValue(':new_chat_photo', self::entitiesArrayToJson($message->getNewChatPhoto())); + $sth->bindValue(':new_chat_photo', self::entitiesArrayToJson($message->getNewChatPhoto() ?: null)); $sth->bindValue(':delete_chat_photo', $message->getDeleteChatPhoto()); $sth->bindValue(':group_chat_created', $message->getGroupChatCreated()); $sth->bindValue(':supergroup_chat_created', $message->getSupergroupChatCreated()); @@ -1058,7 +1058,7 @@ public static function insertEditedMessageRequest(Message $edited_message) $sth->bindValue(':user_id', $user_id); $sth->bindValue(':edit_date', $edit_date); $sth->bindValue(':text', $edited_message->getText()); - $sth->bindValue(':entities', self::entitiesArrayToJson($edited_message->getEntities())); + $sth->bindValue(':entities', self::entitiesArrayToJson($edited_message->getEntities() ?: null)); $sth->bindValue(':caption', $edited_message->getCaption()); return $sth->execute(); diff --git a/src/Entities/Games/Game.php b/src/Entities/Games/Game.php index e6e4b5179..da9ad51c2 100644 --- a/src/Entities/Games/Game.php +++ b/src/Entities/Games/Game.php @@ -47,13 +47,11 @@ protected function subEntities() * This method overrides the default getPhoto method * and returns a nice array of PhotoSize objects. * - * @return null|\Longman\TelegramBot\Entities\PhotoSize[] + * @return PhotoSize[] */ public function getPhoto() { - $pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'photo'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(PhotoSize::class, 'photo'); } /** @@ -62,12 +60,10 @@ public function getPhoto() * This method overrides the default getTextEntities method * and returns a nice array of MessageEntity objects. * - * @return null|\Longman\TelegramBot\Entities\MessageEntity[] + * @return MessageEntity[] */ public function getTextEntities() { - $pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'text_entities'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(MessageEntity::class, 'text_entities'); } } diff --git a/src/Entities/Message.php b/src/Entities/Message.php index 674e74ac0..032880530 100644 --- a/src/Entities/Message.php +++ b/src/Entities/Message.php @@ -118,13 +118,11 @@ public function __construct(array $data, $bot_username = '') * This method overrides the default getPhoto method * and returns a nice array of PhotoSize objects. * - * @return null|PhotoSize[] + * @return PhotoSize[] */ public function getPhoto() { - $pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'photo'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(PhotoSize::class, 'photo'); } /** @@ -133,13 +131,11 @@ public function getPhoto() * This method overrides the default getNewChatPhoto method * and returns a nice array of PhotoSize objects. * - * @return null|PhotoSize[] + * @return PhotoSize[] */ public function getNewChatPhoto() { - $pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'new_chat_photo'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(PhotoSize::class, 'new_chat_photo'); } /** @@ -148,13 +144,11 @@ public function getNewChatPhoto() * This method overrides the default getNewChatMembers method * and returns a nice array of User objects. * - * @return null|User[] + * @return User[] */ public function getNewChatMembers() { - $pretty_array = $this->makePrettyObjectArray(User::class, 'new_chat_members'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(User::class, 'new_chat_members'); } /** @@ -163,13 +157,11 @@ public function getNewChatMembers() * This method overrides the default getEntities method * and returns a nice array of MessageEntity objects. * - * @return null|MessageEntity[] + * @return MessageEntity[] */ public function getEntities() { - $pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'entities'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(MessageEntity::class, 'entities'); } /** @@ -178,13 +170,11 @@ public function getEntities() * This method overrides the default getCaptionEntities method * and returns a nice array of MessageEntity objects. * - * @return null|MessageEntity[] + * @return MessageEntity[] */ public function getCaptionEntities() { - $pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'caption_entities'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(MessageEntity::class, 'caption_entities'); } /** diff --git a/src/Entities/Poll.php b/src/Entities/Poll.php index 36d315a5d..697c15ceb 100644 --- a/src/Entities/Poll.php +++ b/src/Entities/Poll.php @@ -39,12 +39,10 @@ protected function subEntities() * This method overrides the default getOptions method * and returns a nice array of PollOption objects. * - * @return null|PollOption[] + * @return PollOption[] */ public function getOptions() { - $pretty_array = $this->makePrettyObjectArray(PollOption::class, 'options'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(PollOption::class, 'options'); } } diff --git a/src/Entities/StickerSet.php b/src/Entities/StickerSet.php index cba3204d4..bc0bed19e 100644 --- a/src/Entities/StickerSet.php +++ b/src/Entities/StickerSet.php @@ -27,12 +27,10 @@ class StickerSet extends Entity * This method overrides the default getStickers method * and returns a nice array of Sticker objects. * - * @return null|Sticker[] + * @return Sticker[] */ public function getStickers() { - $pretty_array = $this->makePrettyObjectArray(Sticker::class, 'stickers'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(Sticker::class, 'stickers'); } } diff --git a/src/Entities/TelegramPassport/EncryptedPassportElement.php b/src/Entities/TelegramPassport/EncryptedPassportElement.php index 4a82777f1..26d622b61 100644 --- a/src/Entities/TelegramPassport/EncryptedPassportElement.php +++ b/src/Entities/TelegramPassport/EncryptedPassportElement.php @@ -50,13 +50,11 @@ protected function subEntities() * This method overrides the default getFiles method * and returns a nice array of PassportFile objects. * - * @return null|PassportFile[] + * @return PassportFile[] */ public function getFiles() { - $pretty_array = $this->makePrettyObjectArray(PassportFile::class, 'files'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(PassportFile::class, 'files'); } /** @@ -65,12 +63,10 @@ public function getFiles() * This method overrides the default getTranslation method * and returns a nice array of PassportFile objects. * - * @return null|PassportFile[] + * @return PassportFile[] */ public function getTranslation() { - $pretty_array = $this->makePrettyObjectArray(PassportFile::class, 'translation'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(PassportFile::class, 'translation'); } } diff --git a/src/Entities/TelegramPassport/PassportData.php b/src/Entities/TelegramPassport/PassportData.php index e1ce862ea..c67cc8957 100644 --- a/src/Entities/TelegramPassport/PassportData.php +++ b/src/Entities/TelegramPassport/PassportData.php @@ -40,12 +40,10 @@ protected function subEntities() * This method overrides the default getData method * and returns a nice array of EncryptedPassportElement objects. * - * @return null|EncryptedPassportElement[] + * @return EncryptedPassportElement[] */ public function getData() { - $pretty_array = $this->makePrettyObjectArray(EncryptedPassportElement::class, 'data'); - - return empty($pretty_array) ? null : $pretty_array; + return $this->makePrettyObjectArray(EncryptedPassportElement::class, 'data'); } } From c77ccd6c00903b18de2c0892b4d20b2a1d8c310f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Tue, 11 Jun 2019 21:27:47 +0200 Subject: [PATCH 2/3] Simplify the process of getting arrays of items from Entities. --- CHANGELOG.md | 1 + src/Entities/Entity.php | 8 +- src/Entities/Games/Game.php | 40 ++------ src/Entities/Message.php | 94 ++----------------- src/Entities/Payments/ShippingOption.php | 19 +--- src/Entities/Poll.php | 22 +---- src/Entities/StickerSet.php | 20 ++-- .../EncryptedPassportElement.php | 48 +++------- .../TelegramPassport/PassportData.php | 18 +--- 9 files changed, 59 insertions(+), 211 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc3d5a05e..2c7ee914e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ### Removed ### Fixed - `forward_date` is now correctly saved to the DB. +- Broken `StickerSet::getStickers()` method. ### Security ## [0.57.0] - 2019-06-01 diff --git a/src/Entities/Entity.php b/src/Entities/Entity.php index 77665442a..8601954c7 100644 --- a/src/Entities/Entity.php +++ b/src/Entities/Entity.php @@ -142,7 +142,13 @@ public function __call($method, $args) $sub_entities = $this->subEntities(); if (isset($sub_entities[$property_name])) { - return new $sub_entities[$property_name]($property, $this->getProperty('bot_username')); + $class = $sub_entities[$property_name]; + + if (is_array($class)) { + return $this->makePrettyObjectArray(reset($class), $property_name); + } + + return new $class($property, $this->getProperty('bot_username')); } return $property; diff --git a/src/Entities/Games/Game.php b/src/Entities/Games/Game.php index da9ad51c2..7cb2a2782 100644 --- a/src/Entities/Games/Game.php +++ b/src/Entities/Games/Game.php @@ -22,10 +22,12 @@ * * @link https://core.telegram.org/bots/api#game * - * @method string getTitle() Title of the game - * @method string getDescription() Description of the game - * @method string getText() Optional. Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters. - * @method Animation getAnimation() Optional. Animation that will be displayed in the game message in chats. Upload via BotFather + * @method string getTitle() Title of the game + * @method string getDescription() Description of the game + * @method PhotoSize[] getPhoto() Photo that will be displayed in the game message in chats. + * @method string getText() Optional. Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters. + * @method MessageEntity[] getTextEntities() Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. + * @method Animation getAnimation() Optional. Animation that will be displayed in the game message in chats. Upload via BotFather **/ class Game extends Entity { @@ -35,35 +37,9 @@ class Game extends Entity protected function subEntities() { return [ - 'photo' => PhotoSize::class, - 'text_entities' => MessageEntity::class, + 'photo' => [PhotoSize::class], + 'text_entities' => [MessageEntity::class], 'animation' => Animation::class, ]; } - - /** - * Photo that will be displayed in the game message in chats. - * - * This method overrides the default getPhoto method - * and returns a nice array of PhotoSize objects. - * - * @return PhotoSize[] - */ - public function getPhoto() - { - return $this->makePrettyObjectArray(PhotoSize::class, 'photo'); - } - - /** - * Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. - * - * This method overrides the default getTextEntities method - * and returns a nice array of MessageEntity objects. - * - * @return MessageEntity[] - */ - public function getTextEntities() - { - return $this->makePrettyObjectArray(MessageEntity::class, 'text_entities'); - } } diff --git a/src/Entities/Message.php b/src/Entities/Message.php index 032880530..69e468b1d 100644 --- a/src/Entities/Message.php +++ b/src/Entities/Message.php @@ -34,10 +34,13 @@ * @method int getEditDate() Optional. Date the message was last edited in Unix time * @method string getMediaGroupId() Optional. The unique identifier of a media message group this message belongs to * @method string getAuthorSignature() Optional. Signature of the post author for messages in channels + * @method MessageEntity[] getEntities() Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text + * @method MessageEntity[] getCaptionEntities() Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption * @method Audio getAudio() Optional. Message is an audio file, information about the file * @method Document getDocument() Optional. Message is a general file, information about the file * @method Animation getAnimation() Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set * @method Game getGame() Optional. Message is a game, information about the game. + * @method PhotoSize[] getPhoto() Optional. Message is a photo, available sizes of the photo * @method Sticker getSticker() Optional. Message is a sticker, information about the sticker * @method Video getVideo() Optional. Message is a video, information about the video * @method Voice getVoice() Optional. Message is a voice message, information about the file @@ -47,8 +50,10 @@ * @method Location getLocation() Optional. Message is a shared location, information about the location * @method Venue getVenue() Optional. Message is a venue, information about the venue * @method Poll getPoll() Optional. Message is a native poll, information about the poll + * @method User[] getNewChatMembers() Optional. A new member(s) was added to the group, information about them (one of this members may be the bot itself) * @method User getLeftChatMember() Optional. A member was removed from the group, information about them (this member may be the bot itself) * @method string getNewChatTitle() Optional. A chat title was changed to this value + * @method PhotoSize[] getNewChatPhoto() Optional. A chat photo was changed to this value * @method bool getDeleteChatPhoto() Optional. Service message: the chat photo was deleted * @method bool getGroupChatCreated() Optional. Service message: the group has been created * @method bool getSupergroupChatCreated() Optional. Service message: the supergroup has been created. This field can't be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup. @@ -74,13 +79,13 @@ protected function subEntities() 'forward_from' => User::class, 'forward_from_chat' => Chat::class, 'reply_to_message' => ReplyToMessage::class, - 'entities' => MessageEntity::class, - 'caption_entities' => MessageEntity::class, + 'entities' => [MessageEntity::class], + 'caption_entities' => [MessageEntity::class], 'audio' => Audio::class, 'document' => Document::class, 'animation' => Animation::class, 'game' => Game::class, - 'photo' => PhotoSize::class, + 'photo' => [PhotoSize::class], 'sticker' => Sticker::class, 'video' => Video::class, 'voice' => Voice::class, @@ -89,9 +94,9 @@ protected function subEntities() 'location' => Location::class, 'venue' => Venue::class, 'poll' => Poll::class, - 'new_chat_members' => User::class, + 'new_chat_members' => [User::class], 'left_chat_member' => User::class, - 'new_chat_photo' => PhotoSize::class, + 'new_chat_photo' => [PhotoSize::class], 'pinned_message' => Message::class, 'invoice' => Invoice::class, 'successful_payment' => SuccessfulPayment::class, @@ -99,84 +104,6 @@ protected function subEntities() ]; } - /** - * Message constructor - * - * @param array $data - * @param string $bot_username - * - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function __construct(array $data, $bot_username = '') - { - parent::__construct($data, $bot_username); - } - - /** - * Optional. Message is a photo, available sizes of the photo - * - * This method overrides the default getPhoto method - * and returns a nice array of PhotoSize objects. - * - * @return PhotoSize[] - */ - public function getPhoto() - { - return $this->makePrettyObjectArray(PhotoSize::class, 'photo'); - } - - /** - * Optional. A chat photo was changed to this value - * - * This method overrides the default getNewChatPhoto method - * and returns a nice array of PhotoSize objects. - * - * @return PhotoSize[] - */ - public function getNewChatPhoto() - { - return $this->makePrettyObjectArray(PhotoSize::class, 'new_chat_photo'); - } - - /** - * Optional. A new member(s) was added to the group, information about them (one of this members may be the bot itself) - * - * This method overrides the default getNewChatMembers method - * and returns a nice array of User objects. - * - * @return User[] - */ - public function getNewChatMembers() - { - return $this->makePrettyObjectArray(User::class, 'new_chat_members'); - } - - /** - * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text - * - * This method overrides the default getEntities method - * and returns a nice array of MessageEntity objects. - * - * @return MessageEntity[] - */ - public function getEntities() - { - return $this->makePrettyObjectArray(MessageEntity::class, 'entities'); - } - - /** - * Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption - * - * This method overrides the default getCaptionEntities method - * and returns a nice array of MessageEntity objects. - * - * @return MessageEntity[] - */ - public function getCaptionEntities() - { - return $this->makePrettyObjectArray(MessageEntity::class, 'caption_entities'); - } - /** * return the entire command like /echo or /echo@bot1 if specified * @@ -254,7 +181,6 @@ public function getText($without_cmd = false) * Bot added in chat * * @return bool - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function botAddedInChat() { diff --git a/src/Entities/Payments/ShippingOption.php b/src/Entities/Payments/ShippingOption.php index 2c0ad8b7e..9f6e9e086 100644 --- a/src/Entities/Payments/ShippingOption.php +++ b/src/Entities/Payments/ShippingOption.php @@ -19,8 +19,9 @@ * * @link https://core.telegram.org/bots/api#shippingoption * - * @method string getId() Shipping option identifier - * @method string getTitle() Option title + * @method string getId() Shipping option identifier + * @method string getTitle() Option title + * @method LabeledPrice[] getPrices() List of price portions **/ class ShippingOption extends Entity { @@ -30,19 +31,7 @@ class ShippingOption extends Entity protected function subEntities() { return [ - 'prices' => LabeledPrice::class, + 'prices' => [LabeledPrice::class], ]; } - - /** - * List of price portions - * - * This method overrides the default getPrices method and returns a nice array - * - * @return LabeledPrice[] - */ - public function getPrices() - { - return $this->makePrettyObjectArray(LabeledPrice::class, 'prices'); - } } diff --git a/src/Entities/Poll.php b/src/Entities/Poll.php index 697c15ceb..a0afa9213 100644 --- a/src/Entities/Poll.php +++ b/src/Entities/Poll.php @@ -17,9 +17,10 @@ * * @link https://core.telegram.org/bots/api#poll * - * @method string getId() Unique poll identifier - * @method string getQuestion() Poll question, 1-255 characters - * @method bool getIsClosed() True, if the poll is closed + * @method string getId() Unique poll identifier + * @method string getQuestion() Poll question, 1-255 characters + * @method PollOption[] getOptions() List of poll options + * @method bool getIsClosed() True, if the poll is closed */ class Poll extends Entity { @@ -29,20 +30,7 @@ class Poll extends Entity protected function subEntities() { return [ - 'options' => PollOption::class, + 'options' => [PollOption::class], ]; } - - /** - * List of poll options - * - * This method overrides the default getOptions method - * and returns a nice array of PollOption objects. - * - * @return PollOption[] - */ - public function getOptions() - { - return $this->makePrettyObjectArray(PollOption::class, 'options'); - } } diff --git a/src/Entities/StickerSet.php b/src/Entities/StickerSet.php index bc0bed19e..eca3e33dc 100644 --- a/src/Entities/StickerSet.php +++ b/src/Entities/StickerSet.php @@ -15,22 +15,20 @@ * * @link https://core.telegram.org/bots/api#stickerset * - * @method string getName() Sticker set name - * @method string getTitle() Sticker set title - * @method bool getContainsMasks() True, if the sticker set contains masks + * @method string getName() Sticker set name + * @method string getTitle() Sticker set title + * @method bool getContainsMasks() True, if the sticker set contains masks + * @method Sticker[] getStickers() List of all set stickers */ class StickerSet extends Entity { /** - * List of all set stickers - * - * This method overrides the default getStickers method - * and returns a nice array of Sticker objects. - * - * @return Sticker[] + * {@inheritdoc} */ - public function getStickers() + protected function subEntities() { - return $this->makePrettyObjectArray(Sticker::class, 'stickers'); + return [ + 'stickers' => [Sticker::class], + ]; } } diff --git a/src/Entities/TelegramPassport/EncryptedPassportElement.php b/src/Entities/TelegramPassport/EncryptedPassportElement.php index 26d622b61..81fbcbfce 100644 --- a/src/Entities/TelegramPassport/EncryptedPassportElement.php +++ b/src/Entities/TelegramPassport/EncryptedPassportElement.php @@ -19,14 +19,16 @@ * * @link https://core.telegram.org/bots/api#encryptedpassportelement * - * @method string getType() Element type. One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”, “phone_number”, “email”. - * @method string getData() Optional. Base64-encoded encrypted Telegram Passport element data provided by the user, available for “personal_details”, “passport”, “driver_license”, “identity_card”, “identity_passport” and “address” types. Can be decrypted and verified using the accompanying EncryptedCredentials. - * @method string getPhoneNumber() Optional. User's verified phone number, available only for “phone_number” type - * @method string getEmail() Optional. User's verified email address, available only for “email” type - * @method PassportFile getFrontSide() Optional. Encrypted file with the front side of the document, provided by the user. Available for “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying EncryptedCredentials. - * @method PassportFile getReverseSide() Optional. Encrypted file with the reverse side of the document, provided by the user. Available for “driver_license” and “identity_card”. The file can be decrypted and verified using the accompanying EncryptedCredentials. - * @method PassportFile getSelfie() Optional. Encrypted file with the selfie of the user holding a document, provided by the user; available for “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying EncryptedCredentials. - * @method string getHash() Base64-encoded element hash for using in PassportElementErrorUnspecified + * @method string getType() Element type. One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”, “phone_number”, “email”. + * @method string getData() Optional. Base64-encoded encrypted Telegram Passport element data provided by the user, available for “personal_details”, “passport”, “driver_license”, “identity_card”, “identity_passport” and “address” types. Can be decrypted and verified using the accompanying EncryptedCredentials. + * @method string getPhoneNumber() Optional. User's verified phone number, available only for “phone_number” type + * @method string getEmail() Optional. User's verified email address, available only for “email” type + * @method PassportFile[] getFiles() Optional. Array of encrypted files with documents provided by the user, available for “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials. + * @method PassportFile getFrontSide() Optional. Encrypted file with the front side of the document, provided by the user. Available for “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying EncryptedCredentials. + * @method PassportFile getReverseSide() Optional. Encrypted file with the reverse side of the document, provided by the user. Available for “driver_license” and “identity_card”. The file can be decrypted and verified using the accompanying EncryptedCredentials. + * @method PassportFile getSelfie() Optional. Encrypted file with the selfie of the user holding a document, provided by the user; available for “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying EncryptedCredentials. + * @method PassportFile[] getTranslation() Optional. Array of encrypted files with translated versions of documents provided by the user. Available if requested for “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials. + * @method string getHash() Base64-encoded element hash for using in PassportElementErrorUnspecified **/ class EncryptedPassportElement extends Entity { @@ -36,37 +38,11 @@ class EncryptedPassportElement extends Entity protected function subEntities() { return [ - 'files' => PassportFile::class, + 'files' => [PassportFile::class], 'front_side' => PassportFile::class, 'reverse_side' => PassportFile::class, 'selfie' => PassportFile::class, - 'translation' => PassportFile::class, + 'translation' => [PassportFile::class], ]; } - - /** - * Optional. Array of encrypted files with documents provided by the user, available for “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials. - * - * This method overrides the default getFiles method - * and returns a nice array of PassportFile objects. - * - * @return PassportFile[] - */ - public function getFiles() - { - return $this->makePrettyObjectArray(PassportFile::class, 'files'); - } - - /** - * Optional. Array of encrypted files with translated versions of documents provided by the user. Available if requested for “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials. - * - * This method overrides the default getTranslation method - * and returns a nice array of PassportFile objects. - * - * @return PassportFile[] - */ - public function getTranslation() - { - return $this->makePrettyObjectArray(PassportFile::class, 'translation'); - } } diff --git a/src/Entities/TelegramPassport/PassportData.php b/src/Entities/TelegramPassport/PassportData.php index c67cc8957..9251296c2 100644 --- a/src/Entities/TelegramPassport/PassportData.php +++ b/src/Entities/TelegramPassport/PassportData.php @@ -19,7 +19,8 @@ * * @link https://core.telegram.org/bots/api#passportdata * - * @method EncryptedCredentials getCredentials() Encrypted credentials required to decrypt the data + * @method EncryptedPassportElement[] getData() Array with information about documents and other Telegram Passport elements that was shared with the bot + * @method EncryptedCredentials getCredentials() Encrypted credentials required to decrypt the data **/ class PassportData extends Entity { @@ -29,21 +30,8 @@ class PassportData extends Entity protected function subEntities() { return [ - 'data' => EncryptedPassportElement::class, + 'data' => [EncryptedPassportElement::class], 'credentials' => EncryptedCredentials::class, ]; } - - /** - * Array with information about documents and other Telegram Passport elements that was shared with the bot - * - * This method overrides the default getData method - * and returns a nice array of EncryptedPassportElement objects. - * - * @return EncryptedPassportElement[] - */ - public function getData() - { - return $this->makePrettyObjectArray(EncryptedPassportElement::class, 'data'); - } } From ecd4449a16e0f5bd949db1ab83f6bf07fa63138f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Wed, 12 Jun 2019 15:10:39 +0200 Subject: [PATCH 3/3] Fix all subEntities method visibility. --- src/Entities/CallbackQuery.php | 2 +- src/Entities/Chat.php | 2 +- src/Entities/ChatMember.php | 2 +- src/Entities/Payments/OrderInfo.php | 2 +- src/Entities/Payments/PreCheckoutQuery.php | 2 +- src/Entities/Payments/ShippingQuery.php | 2 +- src/Entities/Payments/SuccessfulPayment.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Entities/CallbackQuery.php b/src/Entities/CallbackQuery.php index f870532ab..cef369b2b 100644 --- a/src/Entities/CallbackQuery.php +++ b/src/Entities/CallbackQuery.php @@ -30,7 +30,7 @@ class CallbackQuery extends Entity /** * {@inheritdoc} */ - public function subEntities() + protected function subEntities() { return [ 'from' => User::class, diff --git a/src/Entities/Chat.php b/src/Entities/Chat.php index e50434352..c4dcb91d5 100644 --- a/src/Entities/Chat.php +++ b/src/Entities/Chat.php @@ -46,7 +46,7 @@ class Chat extends Entity /** * {@inheritdoc} */ - public function subEntities() + protected function subEntities() { return [ 'photo' => ChatPhoto::class, diff --git a/src/Entities/ChatMember.php b/src/Entities/ChatMember.php index 16b71d5a0..ef03dd936 100644 --- a/src/Entities/ChatMember.php +++ b/src/Entities/ChatMember.php @@ -38,7 +38,7 @@ class ChatMember extends Entity /** * {@inheritdoc} */ - public function subEntities() + protected function subEntities() { return [ 'user' => User::class, diff --git a/src/Entities/Payments/OrderInfo.php b/src/Entities/Payments/OrderInfo.php index f57c81bd2..614a1f17a 100644 --- a/src/Entities/Payments/OrderInfo.php +++ b/src/Entities/Payments/OrderInfo.php @@ -29,7 +29,7 @@ class OrderInfo extends Entity /** * {@inheritdoc} */ - public function subEntities() + protected function subEntities() { return [ 'shipping_address' => ShippingAddress::class, diff --git a/src/Entities/Payments/PreCheckoutQuery.php b/src/Entities/Payments/PreCheckoutQuery.php index b86e7647a..a3d36844a 100644 --- a/src/Entities/Payments/PreCheckoutQuery.php +++ b/src/Entities/Payments/PreCheckoutQuery.php @@ -34,7 +34,7 @@ class PreCheckoutQuery extends Entity /** * {@inheritdoc} */ - public function subEntities() + protected function subEntities() { return [ 'from' => User::class, diff --git a/src/Entities/Payments/ShippingQuery.php b/src/Entities/Payments/ShippingQuery.php index 0425254d9..f1cf4bb03 100644 --- a/src/Entities/Payments/ShippingQuery.php +++ b/src/Entities/Payments/ShippingQuery.php @@ -31,7 +31,7 @@ class ShippingQuery extends Entity /** * {@inheritdoc} */ - public function subEntities() + protected function subEntities() { return [ 'from' => User::class, diff --git a/src/Entities/Payments/SuccessfulPayment.php b/src/Entities/Payments/SuccessfulPayment.php index 67e762bfc..cf045211d 100644 --- a/src/Entities/Payments/SuccessfulPayment.php +++ b/src/Entities/Payments/SuccessfulPayment.php @@ -32,7 +32,7 @@ class SuccessfulPayment extends Entity /** * {@inheritdoc} */ - public function subEntities() + protected function subEntities() { return [ 'order_info' => OrderInfo::class,