Skip to content

Commit

Permalink
[fix] DTO lose false values
Browse files Browse the repository at this point in the history
fix #416
  • Loading branch information
fabio-ivona committed Feb 1, 2024
1 parent bee7da0 commit 37756c6
Show file tree
Hide file tree
Showing 28 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/DTO/Animation.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ public function toArray(): array
'mime_type' => $this->mimeType,
'filesize' => $this->filesize,
'thumbnail' => $this->thumbnail?->toArray(),
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ public function toArray(): array
'mime_type' => $this->mimeType,
'filesize' => $this->filesize,
'thumbnail' => $this->thumbnail?->toArray(),
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/CallbackQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ public function toArray(): array
'from' => $this->from->toArray(),
'message' => $this->message?->toArray(),
'data' => $this->data->toArray(),
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public function toArray(): array
'id' => $this->id,
'type' => $this->type,
'title' => $this->title,
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/ChatMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public function toArray(): array
'custom_title' => $this->custom_title,
'is_member' => $this->is_member,
'until_date' => $this->until_date,
]);
], fn ($value) => $value !== null);
}
}
22 changes: 11 additions & 11 deletions src/DTO/ChatMemberUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ public static function fromArray(array $data): ChatMemberUpdate
return $chatMemberUpdate;
}

public function toArray(): array
{
return array_filter([
'chat' => $this->chat->toArray(),
'from' => $this->from->toArray(),
'date' => $this->date->toISOString(),
'previous' => $this->previous->toArray(),
'new' => $this->new->toArray(),
]);
}

public function date(): CarbonInterface
{
return $this->date;
Expand All @@ -77,4 +66,15 @@ public function new(): ChatMember
{
return $this->new;
}

public function toArray(): array
{
return array_filter([
'chat' => $this->chat->toArray(),
'from' => $this->from->toArray(),
'date' => $this->date->toISOString(),
'previous' => $this->previous->toArray(),
'new' => $this->new->toArray(),
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ public function toArray(): array
'last_name' => $this->last_name,
'user_id' => $this->user_id,
'vcard' => $this->vcard,
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ public function toArray(): array
'mime_type' => $this->mimeType,
'filesize' => $this->filesize,
'thumbnail' => $this->thumbnail?->toArray(),
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/InlineQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ public function toArray(): array
'offset' => $this->offset,
'chat_type' => $this->chatType,
'location' => $this->location,
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/InlineQueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function keyboard(Keyboard $keyboard): static
*/
public function toArray(): array
{
$data = array_filter($this->data()) + [
$data = array_filter($this->data(), fn ($value) => $value !== null) + [
'id' => $this->id,
'type' => $this->type,
];
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/InlineQueryResultArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ public function data(): array
];
}

return $data;
return array_filter($data, fn ($value) => $value !== null);
}
}
4 changes: 2 additions & 2 deletions src/DTO/InlineQueryResultAudio.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ public function markdownV2(): static
*/
public function data(): array
{
return [
return array_filter([
'audio_url' => $this->url,
'title' => $this->title,
'caption' => $this->caption,
'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
'performer' => $this->performer,
'audio_duration' => $this->duration,
];
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/InlineQueryResultContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ public function data(): array
];
}

return $data;
return array_filter($data, fn ($value) => $value !== null);
}
}
4 changes: 2 additions & 2 deletions src/DTO/InlineQueryResultDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function markdownV2(): static
*/
public function data(): array
{
return [
return array_filter([
'title' => $this->title,
'caption' => $this->caption,
'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
Expand All @@ -102,6 +102,6 @@ public function data(): array
'thumb_url' => $this->thumbUrl,
'thumb_width' => $this->thumbWidth,
'thumb_height' => $this->thumbHeight,
];
], fn ($value) => $value !== null);
}
}
4 changes: 2 additions & 2 deletions src/DTO/InlineQueryResultGif.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function markdownV2(): static
*/
public function data(): array
{
return [
return array_filter([
'gif_url' => $this->url,
'thumb_url' => $this->thumbUrl,
'gif_width' => $this->width,
Expand All @@ -99,6 +99,6 @@ public function data(): array
'title' => $this->title,
'caption' => $this->caption,
'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
];
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/InlineQueryResultLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ public function data(): array
];
}

return $data;
return array_filter($data, fn ($value) => $value !== null);
}
}
4 changes: 2 additions & 2 deletions src/DTO/InlineQueryResultMpeg4Gif.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function markdownV2(): static
*/
public function data(): array
{
return [
return array_filter([
'mpeg4_url' => $this->mpeg4Url,
'mpeg4_width' => $this->mpeg4Width,
'mpeg4_height' => $this->mpeg4Height,
Expand All @@ -108,6 +108,6 @@ public function data(): array
'title' => $this->title,
'caption' => $this->caption,
'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
];
], fn ($value) => $value !== null);
}
}
4 changes: 2 additions & 2 deletions src/DTO/InlineQueryResultPhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function markdownV2(): static
*/
public function data(): array
{
return [
return array_filter([
'photo_url' => $this->url,
'thumb_url' => $this->thumbUrl,
'photo_width' => $this->width,
Expand All @@ -99,6 +99,6 @@ public function data(): array
'caption' => $this->caption,
'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
'description' => $this->description,
];
], fn ($value) => $value !== null);
}
}
4 changes: 2 additions & 2 deletions src/DTO/InlineQueryResultVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function markdownV2(): static
*/
public function data(): array
{
return [
return array_filter([
'video_url' => $this->url,
'mime_type' => $this->mimeType,
'thumb_url' => $this->thumbUrl,
Expand All @@ -105,6 +105,6 @@ public function data(): array
'video_height' => $this->height,
'video_duration' => $this->duration,
'description' => $this->description,
];
], fn ($value) => $value !== null);
}
}
4 changes: 2 additions & 2 deletions src/DTO/InlineQueryResultVoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public function markdownV2(): static
*/
public function data(): array
{
return [
return array_filter([
'voice_url' => $this->url,
'title' => $this->title,
'caption' => $this->caption,
'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
'voice_duration' => $this->duration,
];
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public function toArray(): array
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'accuracy' => $this->accuracy,
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,6 @@ public function toArray(): array
'new_chat_members' => $this->newChatMembers->toArray(),
'left_chat_member' => $this->leftChatMember,
'web_app_data' => $this->webAppData,
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public function toArray(): array
'width' => $this->width,
'height' => $this->height,
'filesize' => $this->filesize,
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/TelegramUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ public function toArray(): array
'callback_query' => $this->callbackQuery?->toArray(),
'bot_chat_status_change' => $this->botChatStatusChange?->toArray(),
'inline_query' => $this->inlineQuery?->toArray(),
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ public function toArray(): array
'last_name' => $this->lastName,
'username' => $this->username,
'language_code' => $this->languageCode,
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public function toArray(): array
'mime_type' => $this->mimeType,
'filesize' => $this->filesize,
'thumbnail' => $this->thumbnail?->toArray(),
]);
], fn ($value) => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/DTO/Voice.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ public function toArray(): array
'duration' => $this->duration,
'mime_type' => $this->mimeType,
'filesize' => $this->filesize,
]);
], fn ($value) => $value !== null);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-
id: 123456
message: { id: 42, date: '2022-03-05T21:45:36.000000Z', text: /start, from: { id: 444, first_name: John, last_name: Smith, username: john_smith, language_code: en }, chat: { id: '987654', type: private, title: john_smith } }
message: { id: 42, date: '2022-03-05T21:45:36.000000Z', text: /start, protected: false, from: { id: 444, is_bot: false, first_name: John, last_name: Smith, username: john_smith, language_code: en }, chat: { id: '987654', type: private, title: john_smith }, photos: { }, new_chat_members: { } }
-
id: 123457
message: { id: 99, date: '2022-03-05T22:35:36.000000Z', text: 'Hello world!', from: { id: 8974, is_bot: true, first_name: 'Test Bot', username: test_bot }, chat: { id: '-987455499', type: group, title: 'Bot Test Chat' } }
message: { id: 99, date: '2022-03-05T22:35:36.000000Z', text: 'Hello world!', protected: false, from: { id: 8974, is_bot: true, first_name: 'Test Bot', last_name: '', username: test_bot, language_code: '' }, chat: { id: '-987455499', type: group, title: 'Bot Test Chat' }, photos: { }, new_chat_members: { } }

0 comments on commit 37756c6

Please sign in to comment.