Return an empty array for Entity properties with no items, instead of `null`

parent 89af4d43
...@@ -7,6 +7,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -7,6 +7,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Added ### Added
### Changed ### Changed
- Use PSR-12 for code style. - Use PSR-12 for code style.
- [:exclamation:][unreleased-bc] Return an empty array for Entity properties with no items, instead of `null`.
### Deprecated ### Deprecated
### Removed ### Removed
### Fixed ### Fixed
...@@ -264,6 +265,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -264,6 +265,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Move `hideKeyboard` to `removeKeyboard`. - Move `hideKeyboard` to `removeKeyboard`.
[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/unreleased.sql [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.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-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 [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
......
...@@ -844,7 +844,7 @@ class DB ...@@ -844,7 +844,7 @@ class DB
$sth->bindValue(':id', $poll->getId()); $sth->bindValue(':id', $poll->getId());
$sth->bindValue(':question', $poll->getQuestion()); $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(':is_closed', $poll->getIsClosed());
$sth->bindValue(':created_at', self::getTimestamp()); $sth->bindValue(':created_at', self::getTimestamp());
...@@ -976,13 +976,13 @@ class DB ...@@ -976,13 +976,13 @@ class DB
$sth->bindValue(':media_group_id', $message->getMediaGroupId()); $sth->bindValue(':media_group_id', $message->getMediaGroupId());
$sth->bindValue(':author_signature', $message->getAuthorSignature()); $sth->bindValue(':author_signature', $message->getAuthorSignature());
$sth->bindValue(':text', $message->getText()); $sth->bindValue(':text', $message->getText());
$sth->bindValue(':entities', self::entitiesArrayToJson($message->getEntities())); $sth->bindValue(':entities', self::entitiesArrayToJson($message->getEntities() ?: null));
$sth->bindValue(':caption_entities', self::entitiesArrayToJson($message->getCaptionEntities())); $sth->bindValue(':caption_entities', self::entitiesArrayToJson($message->getCaptionEntities() ?: null));
$sth->bindValue(':audio', $message->getAudio()); $sth->bindValue(':audio', $message->getAudio());
$sth->bindValue(':document', $message->getDocument()); $sth->bindValue(':document', $message->getDocument());
$sth->bindValue(':animation', $message->getAnimation()); $sth->bindValue(':animation', $message->getAnimation());
$sth->bindValue(':game', $message->getGame()); $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(':sticker', $message->getSticker());
$sth->bindValue(':video', $message->getVideo()); $sth->bindValue(':video', $message->getVideo());
$sth->bindValue(':voice', $message->getVoice()); $sth->bindValue(':voice', $message->getVoice());
...@@ -995,7 +995,7 @@ class DB ...@@ -995,7 +995,7 @@ class DB
$sth->bindValue(':new_chat_members', $new_chat_members_ids); $sth->bindValue(':new_chat_members', $new_chat_members_ids);
$sth->bindValue(':left_chat_member', $left_chat_member_id); $sth->bindValue(':left_chat_member', $left_chat_member_id);
$sth->bindValue(':new_chat_title', $message->getNewChatTitle()); $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(':delete_chat_photo', $message->getDeleteChatPhoto());
$sth->bindValue(':group_chat_created', $message->getGroupChatCreated()); $sth->bindValue(':group_chat_created', $message->getGroupChatCreated());
$sth->bindValue(':supergroup_chat_created', $message->getSupergroupChatCreated()); $sth->bindValue(':supergroup_chat_created', $message->getSupergroupChatCreated());
...@@ -1058,7 +1058,7 @@ class DB ...@@ -1058,7 +1058,7 @@ class DB
$sth->bindValue(':user_id', $user_id); $sth->bindValue(':user_id', $user_id);
$sth->bindValue(':edit_date', $edit_date); $sth->bindValue(':edit_date', $edit_date);
$sth->bindValue(':text', $edited_message->getText()); $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()); $sth->bindValue(':caption', $edited_message->getCaption());
return $sth->execute(); return $sth->execute();
......
...@@ -47,13 +47,11 @@ class Game extends Entity ...@@ -47,13 +47,11 @@ class Game extends Entity
* This method overrides the default getPhoto method * This method overrides the default getPhoto method
* and returns a nice array of PhotoSize objects. * and returns a nice array of PhotoSize objects.
* *
* @return null|\Longman\TelegramBot\Entities\PhotoSize[] * @return PhotoSize[]
*/ */
public function getPhoto() public function getPhoto()
{ {
$pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'photo'); return $this->makePrettyObjectArray(PhotoSize::class, 'photo');
return empty($pretty_array) ? null : $pretty_array;
} }
/** /**
...@@ -62,12 +60,10 @@ class Game extends Entity ...@@ -62,12 +60,10 @@ class Game extends Entity
* This method overrides the default getTextEntities method * This method overrides the default getTextEntities method
* and returns a nice array of MessageEntity objects. * and returns a nice array of MessageEntity objects.
* *
* @return null|\Longman\TelegramBot\Entities\MessageEntity[] * @return MessageEntity[]
*/ */
public function getTextEntities() public function getTextEntities()
{ {
$pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'text_entities'); return $this->makePrettyObjectArray(MessageEntity::class, 'text_entities');
return empty($pretty_array) ? null : $pretty_array;
} }
} }
...@@ -118,13 +118,11 @@ class Message extends Entity ...@@ -118,13 +118,11 @@ class Message extends Entity
* This method overrides the default getPhoto method * This method overrides the default getPhoto method
* and returns a nice array of PhotoSize objects. * and returns a nice array of PhotoSize objects.
* *
* @return null|PhotoSize[] * @return PhotoSize[]
*/ */
public function getPhoto() public function getPhoto()
{ {
$pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'photo'); return $this->makePrettyObjectArray(PhotoSize::class, 'photo');
return empty($pretty_array) ? null : $pretty_array;
} }
/** /**
...@@ -133,13 +131,11 @@ class Message extends Entity ...@@ -133,13 +131,11 @@ class Message extends Entity
* This method overrides the default getNewChatPhoto method * This method overrides the default getNewChatPhoto method
* and returns a nice array of PhotoSize objects. * and returns a nice array of PhotoSize objects.
* *
* @return null|PhotoSize[] * @return PhotoSize[]
*/ */
public function getNewChatPhoto() public function getNewChatPhoto()
{ {
$pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'new_chat_photo'); return $this->makePrettyObjectArray(PhotoSize::class, 'new_chat_photo');
return empty($pretty_array) ? null : $pretty_array;
} }
/** /**
...@@ -148,13 +144,11 @@ class Message extends Entity ...@@ -148,13 +144,11 @@ class Message extends Entity
* This method overrides the default getNewChatMembers method * This method overrides the default getNewChatMembers method
* and returns a nice array of User objects. * and returns a nice array of User objects.
* *
* @return null|User[] * @return User[]
*/ */
public function getNewChatMembers() public function getNewChatMembers()
{ {
$pretty_array = $this->makePrettyObjectArray(User::class, 'new_chat_members'); return $this->makePrettyObjectArray(User::class, 'new_chat_members');
return empty($pretty_array) ? null : $pretty_array;
} }
/** /**
...@@ -163,13 +157,11 @@ class Message extends Entity ...@@ -163,13 +157,11 @@ class Message extends Entity
* This method overrides the default getEntities method * This method overrides the default getEntities method
* and returns a nice array of MessageEntity objects. * and returns a nice array of MessageEntity objects.
* *
* @return null|MessageEntity[] * @return MessageEntity[]
*/ */
public function getEntities() public function getEntities()
{ {
$pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'entities'); return $this->makePrettyObjectArray(MessageEntity::class, 'entities');
return empty($pretty_array) ? null : $pretty_array;
} }
/** /**
...@@ -178,13 +170,11 @@ class Message extends Entity ...@@ -178,13 +170,11 @@ class Message extends Entity
* This method overrides the default getCaptionEntities method * This method overrides the default getCaptionEntities method
* and returns a nice array of MessageEntity objects. * and returns a nice array of MessageEntity objects.
* *
* @return null|MessageEntity[] * @return MessageEntity[]
*/ */
public function getCaptionEntities() public function getCaptionEntities()
{ {
$pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'caption_entities'); return $this->makePrettyObjectArray(MessageEntity::class, 'caption_entities');
return empty($pretty_array) ? null : $pretty_array;
} }
/** /**
......
...@@ -39,12 +39,10 @@ class Poll extends Entity ...@@ -39,12 +39,10 @@ class Poll extends Entity
* This method overrides the default getOptions method * This method overrides the default getOptions method
* and returns a nice array of PollOption objects. * and returns a nice array of PollOption objects.
* *
* @return null|PollOption[] * @return PollOption[]
*/ */
public function getOptions() public function getOptions()
{ {
$pretty_array = $this->makePrettyObjectArray(PollOption::class, 'options'); return $this->makePrettyObjectArray(PollOption::class, 'options');
return empty($pretty_array) ? null : $pretty_array;
} }
} }
...@@ -27,12 +27,10 @@ class StickerSet extends Entity ...@@ -27,12 +27,10 @@ class StickerSet extends Entity
* This method overrides the default getStickers method * This method overrides the default getStickers method
* and returns a nice array of Sticker objects. * and returns a nice array of Sticker objects.
* *
* @return null|Sticker[] * @return Sticker[]
*/ */
public function getStickers() public function getStickers()
{ {
$pretty_array = $this->makePrettyObjectArray(Sticker::class, 'stickers'); return $this->makePrettyObjectArray(Sticker::class, 'stickers');
return empty($pretty_array) ? null : $pretty_array;
} }
} }
...@@ -50,13 +50,11 @@ class EncryptedPassportElement extends Entity ...@@ -50,13 +50,11 @@ class EncryptedPassportElement extends Entity
* This method overrides the default getFiles method * This method overrides the default getFiles method
* and returns a nice array of PassportFile objects. * and returns a nice array of PassportFile objects.
* *
* @return null|PassportFile[] * @return PassportFile[]
*/ */
public function getFiles() public function getFiles()
{ {
$pretty_array = $this->makePrettyObjectArray(PassportFile::class, 'files'); return $this->makePrettyObjectArray(PassportFile::class, 'files');
return empty($pretty_array) ? null : $pretty_array;
} }
/** /**
...@@ -65,12 +63,10 @@ class EncryptedPassportElement extends Entity ...@@ -65,12 +63,10 @@ class EncryptedPassportElement extends Entity
* This method overrides the default getTranslation method * This method overrides the default getTranslation method
* and returns a nice array of PassportFile objects. * and returns a nice array of PassportFile objects.
* *
* @return null|PassportFile[] * @return PassportFile[]
*/ */
public function getTranslation() public function getTranslation()
{ {
$pretty_array = $this->makePrettyObjectArray(PassportFile::class, 'translation'); return $this->makePrettyObjectArray(PassportFile::class, 'translation');
return empty($pretty_array) ? null : $pretty_array;
} }
} }
...@@ -40,12 +40,10 @@ class PassportData extends Entity ...@@ -40,12 +40,10 @@ class PassportData extends Entity
* This method overrides the default getData method * This method overrides the default getData method
* and returns a nice array of EncryptedPassportElement objects. * and returns a nice array of EncryptedPassportElement objects.
* *
* @return null|EncryptedPassportElement[] * @return EncryptedPassportElement[]
*/ */
public function getData() public function getData()
{ {
$pretty_array = $this->makePrettyObjectArray(EncryptedPassportElement::class, 'data'); return $this->makePrettyObjectArray(EncryptedPassportElement::class, 'data');
return empty($pretty_array) ? null : $pretty_array;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment