Add `getEntity` to `GroupMembershipInterface` to improve typehinting

Created on 16 July 2024, 3 months ago

Problem/Motivation

GroupRelationshipInterface specifies getEntity as returning a EntityInterface. This interface is extended by GroupMembershipInterface and implemented by GroupMembership.

From the rules around how the GroupMembership works we know that the entity that it points to are user entities (I'm assuming this is enforced in code). However, when you know you have an instance of GroupMembershipInterface, tools like PHPStan or your IDE will still think GroupMembershipInterface::getEntity returns a EntityInterface rather than knowing you'll get a UserInterface instance. This requires extra checks, assertions or annotations.

Steps to reproduce

Proposed resolution

Add getEntity as method to GroupMembershipInterface and narrow the type-hint to UserInterface. This is allowed because UserInterface still satisfies EntityInterface

Remaining tasks

User interface changes

API changes

  • GroupMembershipInterface and GroupMembership are now type-hinted to return a UserInterface when calling getEntity

Data model changes

Feature request
Status

Active

Version

3.3

Component

Code

Created by

🇳🇱Netherlands kingdutch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024