Skip to content

Improvement/role type casting#401

Merged
herpaderpaldent merged 6 commits into4.xfrom
improvement/role-type-casting
Apr 27, 2025
Merged

Improvement/role type casting#401
herpaderpaldent merged 6 commits into4.xfrom
improvement/role-type-casting

Conversation

@herpaderpaldent
Copy link
Contributor

No description provided.

This commit introduces a cast for the 'type' property in the Role model using the RoleType enum to enforce type safety. It also refactors the BaseRoleService to use the getType() method, improving clarity and reducing reliance on raw value matching. These changes ensure better maintainability and stricter type adherence.
Simplify the role type comparison by directly using the roleType object instead of its value property. This change ensures consistency and reduces unnecessary property access. Adjust the update method accordingly to reflect this modification.
Replaced the redundant variable assignment in the `getType` method with a direct return statement. This improves code readability and eliminates unnecessary lines without changing functionality.
Replaced the hardcoded `false` with a call to `isModerator`. This ensures the method correctly evaluates whether a user has moderation privileges.
Updated the `Role` model's docblock type hint for `$type` to reflect its usage as `RoleType`. This ensures consistency and clarity in type definitions within the codebase.
@what-the-diff
Copy link

what-the-diff bot commented Apr 27, 2025

PR Summary

  • Updated Role Model
    The 'Role' model now uses the 'RoleType' enumeration for the 'type' property, thus increasing the strictness of data types and preventing invalid data from being assigned.

  • Added Type Casting in Role Model
    Type casting has been incorporated for the 'type' property in the 'Role' model. This guarantees that the property will always be treated as a 'RoleType' enumeration.

  • Refactored setRoleType Method
    The method 'setRoleType' in the 'AbstractRoleService' has been refactored to compare 'RoleType' instances instead of their values. This direct comparison enhances code readability and understanding.

  • Modified getTypeService Method
    The 'getTypeService' method in the 'BaseRoleService' has been modified to work with 'RoleType' instances instead of string values, offering a more specific and safer way to handle role types.

  • Added getType Method
    A new method named 'getType' has been added in 'BaseRoleService'. It is used to fetch the role's type as a 'RoleType' instance, allowing easier and more accurate identification of a role's type.

  • Changed canModerate Method
    The 'canModerate' method in 'OptInRoleService' now returns the result of 'isModerator' instead of always returning false. This reflects the actual moderator status of the role more accurately.

  • Updated Tests
    Tests across various files have been updated to reflect the use of 'RoleType' enumerations instead of string values for role types. These tests ensure that the changes are working as expected.

@herpaderpaldent herpaderpaldent merged commit 568c0d7 into 4.x Apr 27, 2025
2 of 3 checks passed
@herpaderpaldent herpaderpaldent deleted the improvement/role-type-casting branch April 27, 2025 17:24
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