diff --git a/src/Discord/Parts/Guild/Guild.php b/src/Discord/Parts/Guild/Guild.php index 6eb43c2a2..981f9bfb4 100644 --- a/src/Discord/Parts/Guild/Guild.php +++ b/src/Discord/Parts/Guild/Guild.php @@ -192,7 +192,6 @@ class Guild extends Part 'splash', 'discovery_splash', 'features', - 'emojis', 'banner', 'owner_id', 'application_id', @@ -203,7 +202,6 @@ class Guild extends Part 'widget_enabled', 'widget_channel_id', 'verification_level', - 'roles', 'default_message_notifications', 'hub_type', 'mfa_level', @@ -223,7 +221,6 @@ class Guild extends Part 'approximate_presence_count', 'welcome_screen', 'nsfw_level', - 'stickers', 'premium_progress_bar_enabled', // events @@ -262,6 +259,9 @@ class Guild extends Part 'feature_verified', 'feature_vip_regions', 'feature_welcome_screen_enabled', + 'emojis', + 'roles', + 'stickers', ]; /** @@ -293,14 +293,40 @@ class Guild extends Part /** * @inheritDoc - * - * @todo move each repository fill to the setAttributes methods */ public function fill(array $attributes): void { parent::fill($attributes); - foreach ($attributes['roles'] ?? [] as $role) { + if (isset($attributes['roles'])) { + $this->setRolesAttribute($attributes['roles']); + } + + if (isset($attributes['emojis'])) { + $this->setEmojisAttribute($attributes['emojis']); + } + + if (isset($attributes['stickers'])) { + $this->setStickersAttribute($attributes['stickers']); + } + + // @todo move each repository fill to the setChannelAttributes methods? + foreach ($attributes['channels'] ?? [] as $channel) { + $channel = (array) $channel; + /** @var Channel */ + if ($channelPart = $this->channels->offsetGet($channel['id'])) { + $channelPart->fill($channel); + } + $this->channels->pushItem($channelPart ?: $this->channels->create($channel, true)); + } + } + + /** + * @inheritDoc + */ + protected function setRolesAttribute(?array $roles): void + { + foreach ($roles ?? [] as $role) { $role = (array) $role; /** @var Role */ if ($rolePart = $this->roles->offsetGet($role['id'])) { @@ -309,7 +335,15 @@ public function fill(array $attributes): void $this->roles->pushItem($rolePart ?: $this->roles->create($role, $this->created)); } - foreach ($attributes['emojis'] ?? [] as $emoji) { + $this->attributes['roles'] = $roles; + } + + /** + * @inheritDoc + */ + protected function setEmojisAttribute(?array $emojis): void + { + foreach ($emojis ?? [] as $emoji) { $emoji = (array) $emoji; /** @var Emoji */ if ($emojiPart = $this->emojis->offsetGet($emoji['id'])) { @@ -318,7 +352,15 @@ public function fill(array $attributes): void $this->emojis->pushItem($emojiPart ?: $this->emojis->create($emoji, $this->created)); } - foreach ($attributes['stickers'] ?? [] as $sticker) { + $this->attributes['emojis'] = $emojis; + } + + /** + * @inheritDoc + */ + protected function setStickersAttribute(?array $stickers): void + { + foreach ($stickers ?? [] as $sticker) { $sticker = (array) $sticker; /** @var Sticker */ if ($stickerPart = $this->stickers->offsetGet($sticker['id'])) { @@ -327,14 +369,7 @@ public function fill(array $attributes): void $this->stickers->pushItem($stickerPart ?: $this->stickers->create($sticker, $this->created)); } - foreach ($attributes['channels'] ?? [] as $channel) { - $channel = (array) $channel; - /** @var Channel */ - if ($channelPart = $this->channels->offsetGet($channel['id'])) { - $channelPart->fill($channel); - } - $this->channels->pushItem($channelPart ?: $this->channels->create($channel, true)); - } + $this->attributes['stickers'] = $stickers; } /**