Use non-deprecated classes#1435
Conversation
ComponentObject is abstract and can't be instantiated directly
There was a problem hiding this comment.
Pull request overview
This PR aims to refactor Discord component handling to consistently use ComponentObject (instead of the deprecated Component) for component type constants/utilities, and to centralize component type definitions.
Changes:
- Updated component type constant references to use
ComponentObject::TYPE_*. - Refactored message component parsing/mapping and typed collection helpers.
- Adjusted poll-related imports/types in
MessageBuilder.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Discord/Parts/Channel/Message/Component.php |
Updates component type mapping and component attribute parsing to use ComponentObject constants (but currently introduces Part-vs-Builder instantiation issues). |
src/Discord/Builders/MessageBuilder.php |
Changes poll import aliasing and loosens setPoll typing. |
src/Discord/Builders/Components/ComponentObject.php |
Adds an import intended for type mapping centralization (currently unused). |
Comments suppressed due to low confidence (2)
src/Discord/Parts/Channel/Message/Component.php:45
TYPESis used byattributeTypedCollectionHelper()/attributePartHelper()to instantiate Part objects viaFactory::part(). UsingComponentObject::class(a Builder) as the fallback will causenew ComponentObject($discord, ...)to be attempted, which does not match the Part constructor and will break parsing unknown component types. The fallback should stay as the Part component class (e.g.,self::class/Component::class).
public const TYPES = [
0 => Component::class, // Fallback for unknown types
ComponentObject::TYPE_ACTION_ROW => ActionRow::class,
ComponentObject::TYPE_BUTTON => Button::class,
src/Discord/Parts/Channel/Message/Component.php:82
attributeTypedCollectionHelper()expects a Part class name; it uses$class::TYPESto choose a Part subclass and then instantiates it viacreateOf()/Factory::part(). PassingComponentObject::classhere will make it try to create Builder component objects as Parts and will likely error at runtime. This should continue to use the Part component class (e.g.,Component::class) while still usingComponentObject::TYPE_*constants in theTYPESmap.
protected function getComponentsAttribute(): ExCollectionInterface
{
return $this->attributeTypedCollectionHelper(Component::class, 'components');
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * @return $this | ||
| */ | ||
| public function setPoll(Poll|null $poll): self | ||
| public function setPoll($poll = null): self |
There was a problem hiding this comment.
setPoll dropped the Poll|null parameter type but the property/phpdoc and getPoll(): ?Poll still imply only PollCreateRequest (aliased as Poll) should be stored. This makes it easy to accidentally set an invalid poll type and only find out later during serialization/request building. Prefer restoring the typed signature (e.g., ?Poll $poll = null) or, if other types are intentionally supported, update the phpdoc/return types and add validation.
| public function setPoll($poll = null): self | |
| public function setPoll(?Poll $poll = null): self |
| use Discord\Parts\Channel\Message\Component as ComponentPart; | ||
|
|
There was a problem hiding this comment.
The newly added import Component as ComponentPart is unused in this file. Either remove it, or (if the intent was to reference ComponentPart::TYPES as described in the PR) update the code to actually use it so the mapping/source-of-truth is clear.
| use Discord\Parts\Channel\Message\Component as ComponentPart; |
|
This PR has been significantly reduced thanks to some much needed maintenance over the last few months. Component has had its deprecation notice removed, and the ComponentObject class will stay abstract. |
This pull request refactors the Discord component builder classes to consistently use the
ComponentObjectclass for type constants and utility methods, instead of the olderComponentclass. This change improves code clarity and future-proofs the codebase by centralizing component type definitions and related utilities. Additionally, the update introduces an alias for available component types and ensures deprecation notices reference the new standard.Refactoring to use
ComponentObjectfor type constants and utilities:Replaced all instances of
Component::TYPE_*withComponentObject::TYPE_*in component classes such asActionRow,Button,ChannelSelect,Container,File,FileUpload,Label,MediaGallery,MentionableSelect,RoleSelect,Section,SelectMenu,Separator,StringSelect,TextDisplay,TextInput,Thumbnail, andUserSelect. This also includes updating checks and assignments that previously used the old constants. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19]Updated deprecation and usage comments to reference
ComponentObjectinstead ofComponent(e.g., forLabeland select menu types). [1] [2] [3]Centralization of component type mappings:
TYPESinComponentObjectthat referencesComponentPart::TYPES, providing a single source of truth for available component types. [1] [2]