Skip to content

Conversation

valzargaming
Copy link
Member

@valzargaming valzargaming commented Sep 4, 2025

This pull request refactors several builder and part classes to consistently use collection helper classes (Collection, ExCollectionInterface) for managing lists of components, options, and other entities. It also introduces a new trait, DynamicPropertyMutatorTrait, to simplify dynamic property access and mutator logic. Additionally, several attribute getter methods are refactored to use new helper methods, improving code readability and maintainability.

Collection Handling Improvements

  • Refactored CommandBuilder, MessageBuilder, and ModalBuilder classes to use Collection and ExCollectionInterface for managing options and components, replacing raw arrays and ensuring consistent collection handling throughout the codebase. This includes updating property types, getter/setter methods, and internal logic for adding/removing items. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Dynamic Property Access

  • Introduced DynamicPropertyMutatorTrait and applied it to the Component class, enabling dynamic getter and setter methods for properties and reducing boilerplate in property access logic. [1] [2] [3]

Attribute Getter Refactoring

  • Refactored multiple attribute getter methods in Channel, Invite, and Message parts to use new helper methods (attributeCollectionHelper, attributePartHelper, attributeCarbonHelper), improving code clarity and reducing duplication. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Type Annotation and Documentation Updates

  • Updated property and method type annotations and PHPDoc comments to reflect the new collection handling and clarify expected types for options and components. [1] [2] [3] [4] [5] [6]

Dependency Imports

  • Added missing imports for Collection and ExCollectionInterface in relevant files to support the new collection logic. [1] [2]

@valzargaming valzargaming marked this pull request as ready for review September 4, 2025 13:25
@valzargaming
Copy link
Member Author

I'm currently testing this on one of my production bots, though more eyes are always welcome. I'm hoping to have this released with 10.19.0.

@valzargaming valzargaming marked this pull request as draft September 6, 2025 06:04
@valzargaming
Copy link
Member Author

valzargaming commented Sep 6, 2025

Updating getter methods to be guaranteed to return a CollectionInterface seems to have introduced some internal BC with serialization. Many jsonSerialize methods only check to see if the property is set before adding the data to the json output without any regard for if the Collection is empty or null.

{
    "code": 50035,
    "errors": {
        "components": {
            "0": {
                "_errors": [
                    {
                        "code": "MODEL_TYPE_CONVERT",
                        "message": "Expected an object\/dictionary."
                    }
                ]
            }
        }
    }
}

@valzargaming
Copy link
Member Author

valzargaming commented Sep 6, 2025

This should be resolved now. The issue was originating from Collections being converted to an associative array when used inside of Builders. The fix is to simply convert the Collection to a non-associative array when calling jsonSerialize.

@valzargaming valzargaming marked this pull request as ready for review September 6, 2025 07:43
@valzargaming
Copy link
Member Author

Tested and confirmed working, but would like a few other people to test it to make sure nothing critical was missed/broken.

@valzargaming valzargaming requested a review from a team September 6, 2025 07:52
@valzargaming valzargaming merged commit 69c9811 into master Sep 7, 2025
1 check passed
@valzargaming valzargaming deleted the implement-attribute-helper branch September 7, 2025 14:07
@valzargaming valzargaming mentioned this pull request Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant