Skip to content

Use non-deprecated classes#1435

Merged
valzargaming merged 8 commits intomasterfrom
componentobject-implementation
Apr 4, 2026
Merged

Use non-deprecated classes#1435
valzargaming merged 8 commits intomasterfrom
componentobject-implementation

Conversation

@valzargaming
Copy link
Copy Markdown
Member

@valzargaming valzargaming commented Nov 24, 2025

This pull request refactors the Discord component builder classes to consistently use the ComponentObject class for type constants and utility methods, instead of the older Component class. 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 ComponentObject for type constants and utilities:

  • Replaced all instances of Component::TYPE_* with ComponentObject::TYPE_* in component classes such as ActionRow, Button, ChannelSelect, Container, File, FileUpload, Label, MediaGallery, MentionableSelect, RoleSelect, Section, SelectMenu, Separator, StringSelect, TextDisplay, TextInput, Thumbnail, and UserSelect. 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 ComponentObject instead of Component (e.g., for Label and select menu types). [1] [2] [3]

Centralization of component type mappings:

  • Added an alias TYPES in ComponentObject that references ComponentPart::TYPES, providing a single source of truth for available component types. [1] [2]

@valzargaming valzargaming requested a review from a team November 24, 2025 17:54
Copilot AI review requested due to automatic review settings April 4, 2026 10:33
ComponentObject is abstract and can't be instantiated directly
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • TYPES is used by attributeTypedCollectionHelper()/attributePartHelper() to instantiate Part objects via Factory::part(). Using ComponentObject::class (a Builder) as the fallback will cause new 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::TYPES to choose a Part subclass and then instantiates it via createOf()/Factory::part(). Passing ComponentObject::class here 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 using ComponentObject::TYPE_* constants in the TYPES map.
    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
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
public function setPoll($poll = null): self
public function setPoll(?Poll $poll = null): self

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +18
use Discord\Parts\Channel\Message\Component as ComponentPart;

Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
use Discord\Parts\Channel\Message\Component as ComponentPart;

Copilot uses AI. Check for mistakes.
@valzargaming
Copy link
Copy Markdown
Member Author

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.

@valzargaming valzargaming merged commit adc82f7 into master Apr 4, 2026
1 of 2 checks passed
@valzargaming valzargaming deleted the componentobject-implementation branch April 4, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants