Repository: defstudio/telegraph (php)

Issue:
DTO\User loses is_bot=false property when call ...->toArray() method
Hello,

When call `DTO\User` object toArray() method `is_bot = false` property is missing. `array_filter()` removes false values from array.

`vendor/defstudio/telegraph/src/DTO/`
```
public function toArray(): array
    {
        return array_filter([
            'id' => $this->id,
            'is_bot' => $this->isBot,
            'first_name' => $this->firstName,
            'last_name' => $this->lastName,
            'username' => $this->username,
            'language_code' => $this->languageCode,
        ]);
    }
```
<img width="911" alt="Screenshot 2023-10-12 at 01 52 32" src="https://github.com/defstudio/telegraph/assets/84812777/79148cd2-296c-49b6-a4c9-bcd8f7c978eb">

<img width="1057" alt="Screenshot 2023-10-12 at 01 57 28" src="https://github.com/defstudio/telegraph/assets/84812777/776de4c9-06c8-4d68-b1e2-aa6e680ab690">




Pull request description:
[fix] DTO lose false values
fix #416

Patch:
diff --git a/src/DTO/Animation.php b/src/DTO/Animation.php
index 76ccaa65..acc10743 100644
--- a/src/DTO/Animation.php
+++ b/src/DTO/Animation.php
@@ -102,6 +102,6 @@ class Animation implements Arrayable, Downloadable
             'mime_type' => $this->mimeType,
             'filesize' => $this->filesize,
             'thumbnail' => $this->thumbnail?->toArray(),
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/Audio.php b/src/DTO/Audio.php
index a29270bf..623e719d 100644
--- a/src/DTO/Audio.php
+++ b/src/DTO/Audio.php
@@ -92,6 +92,6 @@ class Audio implements Arrayable, Downloadable
             'mime_type' => $this->mimeType,
             'filesize' => $this->filesize,
             'thumbnail' => $this->thumbnail?->toArray(),
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/CallbackQuery.php b/src/DTO/CallbackQuery.php
index 6adcfe18..122c0ccd 100644
--- a/src/DTO/CallbackQuery.php
+++ b/src/DTO/CallbackQuery.php
@@ -81,6 +81,6 @@ class CallbackQuery implements Arrayable
             'from' => $this->from->toArray(),
             'message' => $this->message?->toArray(),
             'data' => $this->data->toArray(),
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/Chat.php b/src/DTO/Chat.php
index c09bb04e..54bade4b 100644
--- a/src/DTO/Chat.php
+++ b/src/DTO/Chat.php
@@ -57,6 +57,6 @@ class Chat implements Arrayable
             'id' => $this->id,
             'type' => $this->type,
             'title' => $this->title,
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/ChatMember.php b/src/DTO/ChatMember.php
index 8c3a15a8..5e05abab 100644
--- a/src/DTO/ChatMember.php
+++ b/src/DTO/ChatMember.php
@@ -88,6 +88,6 @@ class ChatMember implements Arrayable
             'custom_title' => $this->custom_title,
             'is_member' => $this->is_member,
             'until_date' => $this->until_date,
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/ChatMemberUpdate.php b/src/DTO/ChatMemberUpdate.php
index cba7ad16..01a45251 100644
--- a/src/DTO/ChatMemberUpdate.php
+++ b/src/DTO/ChatMemberUpdate.php
@@ -42,17 +42,6 @@ class ChatMemberUpdate implements Arrayable
         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;
@@ -77,4 +66,15 @@ class ChatMemberUpdate implements Arrayable
     {
         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);
+    }
 }
diff --git a/src/DTO/Contact.php b/src/DTO/Contact.php
index 64dcce58..5367a5b1 100644
--- a/src/DTO/Contact.php
+++ b/src/DTO/Contact.php
@@ -65,6 +65,6 @@ class Contact implements Arrayable
             'last_name' => $this->last_name,
             'user_id' => $this->user_id,
             'vcard' => $this->vcard,
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/Document.php b/src/DTO/Document.php
index b44a78de..fff628d2 100644
--- a/src/DTO/Document.php
+++ b/src/DTO/Document.php
@@ -73,6 +73,6 @@ class Document implements Arrayable, Downloadable
             'mime_type' => $this->mimeType,
             'filesize' => $this->filesize,
             'thumbnail' => $this->thumbnail?->toArray(),
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/InlineQuery.php b/src/DTO/InlineQuery.php
index 41e36c3d..cea0405e 100644
--- a/src/DTO/InlineQuery.php
+++ b/src/DTO/InlineQuery.php
@@ -87,6 +87,6 @@ class InlineQuery implements Arrayable
             'offset' => $this->offset,
             'chat_type' => $this->chatType,
             'location' => $this->location,
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/InlineQueryResult.php b/src/DTO/InlineQueryResult.php
index 0c5e330e..befdbef4 100644
--- a/src/DTO/InlineQueryResult.php
+++ b/src/DTO/InlineQueryResult.php
@@ -33,7 +33,7 @@ abstract class InlineQueryResult
      */
     public function toArray(): array
     {
-        $data = array_filter($this->data()) + [
+        $data = array_filter($this->data(), fn ($value) => $value !== null) + [
           'id' => $this->id,
           'type' => $this->type,
         ];
diff --git a/src/DTO/InlineQueryResultArticle.php b/src/DTO/InlineQueryResultArticle.php
index 56d580a4..2cacafea 100644
--- a/src/DTO/InlineQueryResultArticle.php
+++ b/src/DTO/InlineQueryResultArticle.php
@@ -115,6 +115,6 @@ class InlineQueryResultArticle extends InlineQueryResult
             ];
         }
 
-        return $data;
+        return array_filter($data, fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/InlineQueryResultAudio.php b/src/DTO/InlineQueryResultAudio.php
index a945dcd9..3bf5ac65 100644
--- a/src/DTO/InlineQueryResultAudio.php
+++ b/src/DTO/InlineQueryResultAudio.php
@@ -74,13 +74,13 @@ class InlineQueryResultAudio extends InlineQueryResult
      */
     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);
     }
 }
diff --git a/src/DTO/InlineQueryResultContact.php b/src/DTO/InlineQueryResultContact.php
index 7202793b..b73110d8 100644
--- a/src/DTO/InlineQueryResultContact.php
+++ b/src/DTO/InlineQueryResultContact.php
@@ -109,6 +109,6 @@ class InlineQueryResultContact extends InlineQueryResult
             ];
         }
 
-        return $data;
+        return array_filter($data, fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/InlineQueryResultDocument.php b/src/DTO/InlineQueryResultDocument.php
index f64b0b27..c1cf77a1 100644
--- a/src/DTO/InlineQueryResultDocument.php
+++ b/src/DTO/InlineQueryResultDocument.php
@@ -92,7 +92,7 @@ class InlineQueryResultDocument extends InlineQueryResult
      */
     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),
@@ -102,6 +102,6 @@ class InlineQueryResultDocument extends InlineQueryResult
             'thumb_url' => $this->thumbUrl,
             'thumb_width' => $this->thumbWidth,
             'thumb_height' => $this->thumbHeight,
-        ];
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/InlineQueryResultGif.php b/src/DTO/InlineQueryResultGif.php
index 9ffc3717..944d283f 100644
--- a/src/DTO/InlineQueryResultGif.php
+++ b/src/DTO/InlineQueryResultGif.php
@@ -90,7 +90,7 @@ class InlineQueryResultGif extends InlineQueryResult
      */
     public function data(): array
     {
-        return [
+        return array_filter([
             'gif_url' => $this->url,
             'thumb_url' => $this->thumbUrl,
             'gif_width' => $this->width,
@@ -99,6 +99,6 @@ class InlineQueryResultGif extends InlineQueryResult
             'title' => $this->title,
             'caption' => $this->caption,
             'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
-        ];
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/InlineQueryResultLocation.php b/src/DTO/InlineQueryResultLocation.php
index ae9640d2..d84687fc 100644
--- a/src/DTO/InlineQueryResultLocation.php
+++ b/src/DTO/InlineQueryResultLocation.php
@@ -130,6 +130,6 @@ class InlineQueryResultLocation extends InlineQueryResult
             ];
         }
 
-        return $data;
+        return array_filter($data, fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/InlineQueryResultMpeg4Gif.php b/src/DTO/InlineQueryResultMpeg4Gif.php
index e846e5c8..22e29789 100644
--- a/src/DTO/InlineQueryResultMpeg4Gif.php
+++ b/src/DTO/InlineQueryResultMpeg4Gif.php
@@ -98,7 +98,7 @@ class InlineQueryResultMpeg4Gif extends InlineQueryResult
      */
     public function data(): array
     {
-        return [
+        return array_filter([
             'mpeg4_url' => $this->mpeg4Url,
             'mpeg4_width' => $this->mpeg4Width,
             'mpeg4_height' => $this->mpeg4Height,
@@ -108,6 +108,6 @@ class InlineQueryResultMpeg4Gif extends InlineQueryResult
             'title' => $this->title,
             'caption' => $this->caption,
             'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
-        ];
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/InlineQueryResultPhoto.php b/src/DTO/InlineQueryResultPhoto.php
index c951ad9c..8b6d1a2b 100644
--- a/src/DTO/InlineQueryResultPhoto.php
+++ b/src/DTO/InlineQueryResultPhoto.php
@@ -90,7 +90,7 @@ class InlineQueryResultPhoto extends InlineQueryResult
      */
     public function data(): array
     {
-        return [
+        return array_filter([
             'photo_url' => $this->url,
             'thumb_url' => $this->thumbUrl,
             'photo_width' => $this->width,
@@ -99,6 +99,6 @@ class InlineQueryResultPhoto extends InlineQueryResult
             'caption' => $this->caption,
             'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
             'description' => $this->description,
-        ];
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/InlineQueryResultVideo.php b/src/DTO/InlineQueryResultVideo.php
index 89d23696..6a983b15 100644
--- a/src/DTO/InlineQueryResultVideo.php
+++ b/src/DTO/InlineQueryResultVideo.php
@@ -94,7 +94,7 @@ class InlineQueryResultVideo extends InlineQueryResult
      */
     public function data(): array
     {
-        return [
+        return array_filter([
             'video_url' => $this->url,
             'mime_type' => $this->mimeType,
             'thumb_url' => $this->thumbUrl,
@@ -105,6 +105,6 @@ class InlineQueryResultVideo extends InlineQueryResult
             'video_height' => $this->height,
             'video_duration' => $this->duration,
             'description' => $this->description,
-        ];
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/InlineQueryResultVoice.php b/src/DTO/InlineQueryResultVoice.php
index e338052e..f7464ca9 100644
--- a/src/DTO/InlineQueryResultVoice.php
+++ b/src/DTO/InlineQueryResultVoice.php
@@ -66,12 +66,12 @@ class InlineQueryResultVoice extends InlineQueryResult
      */
     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);
     }
 }
diff --git a/src/DTO/Location.php b/src/DTO/Location.php
index 0dccb1c9..49beef1f 100644
--- a/src/DTO/Location.php
+++ b/src/DTO/Location.php
@@ -53,6 +53,6 @@ class Location implements Arrayable
             'latitude' => $this->latitude,
             'longitude' => $this->longitude,
             'accuracy' => $this->accuracy,
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/Message.php b/src/DTO/Message.php
index 1de2d3e9..0c898aef 100644
--- a/src/DTO/Message.php
+++ b/src/DTO/Message.php
@@ -316,6 +316,6 @@ class Message implements Arrayable
             'new_chat_members' => $this->newChatMembers->toArray(),
             'left_chat_member' => $this->leftChatMember,
             'web_app_data' => $this->webAppData,
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/Photo.php b/src/DTO/Photo.php
index 068a0c2b..61c13451 100644
--- a/src/DTO/Photo.php
+++ b/src/DTO/Photo.php
@@ -63,6 +63,6 @@ class Photo implements Arrayable, Downloadable
             'width' => $this->width,
             'height' => $this->height,
             'filesize' => $this->filesize,
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/TelegramUpdate.php b/src/DTO/TelegramUpdate.php
index e197fb3e..4babafab 100644
--- a/src/DTO/TelegramUpdate.php
+++ b/src/DTO/TelegramUpdate.php
@@ -103,6 +103,6 @@ class TelegramUpdate implements Arrayable
             'callback_query' => $this->callbackQuery?->toArray(),
             'bot_chat_status_change' => $this->botChatStatusChange?->toArray(),
             'inline_query' => $this->inlineQuery?->toArray(),
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/User.php b/src/DTO/User.php
index 77a60346..bb9cc065 100644
--- a/src/DTO/User.php
+++ b/src/DTO/User.php
@@ -85,6 +85,6 @@ class User implements Arrayable, Storable
             'last_name' => $this->lastName,
             'username' => $this->username,
             'language_code' => $this->languageCode,
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/Video.php b/src/DTO/Video.php
index 40f8e674..ee4716bf 100644
--- a/src/DTO/Video.php
+++ b/src/DTO/Video.php
@@ -100,6 +100,6 @@ class Video implements Arrayable, Downloadable
             'mime_type' => $this->mimeType,
             'filesize' => $this->filesize,
             'thumbnail' => $this->thumbnail?->toArray(),
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }
diff --git a/src/DTO/Voice.php b/src/DTO/Voice.php
index 32eab703..8e325f5e 100644
--- a/src/DTO/Voice.php
+++ b/src/DTO/Voice.php
@@ -65,6 +65,6 @@ class Voice implements Arrayable, Downloadable
             'duration' => $this->duration,
             'mime_type' => $this->mimeType,
             'filesize' => $this->filesize,
-        ]);
+        ], fn ($value) => $value !== null);
     }
 }


Test patch:
diff --git a/tests/__snapshots__/TelegraphBotTest__it_can_poll_for_updates__1.yml b/tests/__snapshots__/TelegraphBotTest__it_can_poll_for_updates__1.yml
index 78ef5f38..5485d2cf 100644
--- a/tests/__snapshots__/TelegraphBotTest__it_can_poll_for_updates__1.yml
+++ b/tests/__snapshots__/TelegraphBotTest__it_can_poll_for_updates__1.yml
@@ -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: {  } }