Reaction class should use Emoji Part rather than stdClass#1422
Reaction class should use Emoji Part rather than stdClass#1422valzargaming wants to merge 4 commits intomasterfrom
Conversation
|
It's unclear if this would introduce a BC in existing bots |
There was a problem hiding this comment.
Pull request overview
This PR updates the Reaction part to initialize its emoji attribute as a proper Emoji Part rather than a generic stdClass, improving type safety and consistency when manipulating reaction emoji data.
Changes:
- Removed the unused
stdClassimport fromReaction.php. - Updated
Reaction::setIdAttribute()to initialize theemojiattribute viaFactory::part(Emoji::class, ...)instead ofnew stdClass().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (! isset($this->attributes['emoji'])) { | ||
| $this->attributes['emoji'] = new stdClass(); | ||
| if ($this->emoji === null) { | ||
| $this->attributes['emoji'] = $this->factory->part(Emoji::class, [], true); |
There was a problem hiding this comment.
When the reaction has no existing emoji attribute, this initializes an Emoji Part with an empty payload. Because getEmojiAttribute() only injects guild_id via attributePartHelper() when converting non-Emoji data, an already-instantiated Emoji will not get guild_id populated, which can break Emoji behavior that relies on guild context (e.g., Emoji::guild, roles resolution). Consider initializing the Emoji Part with ['guild_id' => $this->guild_id] (or otherwise ensuring guild_id is set) when creating it here.
| $this->attributes['emoji'] = $this->factory->part(Emoji::class, [], true); | |
| $this->attributes['emoji'] = $this->factory->part(Emoji::class, ['guild_id' => $this->guild_id], true); |
|
This PR might be pointless thankss to the getEmojiAttribute's attributePartHelper, but should probably be merged anyway just to satisfy the expectation of an Emoji being the value. |
This pull request makes a minor improvement to the
Reactionclass in the Discord package by initializing theemojiattribute with anEmojiobject instead of a genericstdClass. This change enhances type safety and consistency when handling emoji data.setIdAttributemethod ofReaction.php, replaced the initialization of theemojiattribute from astdClassto anEmojiobject for better type safety and clarity.stdClassimport fromReaction.php.