Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Do not require to pass the full user object when only the ID is required #541

Merged
merged 4 commits into from
Jul 23, 2019

Conversation

pfrenssen
Copy link
Contributor

This is part of #487

Most of the methods in the MembershipManager service that deal with users require the full user object to be passed in, but only require the user ID to operate. This requires the calling code to needlessly load the full user entity from the database while they could simply pass in the entity ID.

This PR provides a B/C layer so that existing code keeps working for now.

@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);
Copy link
Collaborator

@MPParsley MPParsley Jul 22, 2019

Choose a reason for hiding this comment

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

Curious to see if this will break any beta blockers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Me too, that's why I added it, in the current code base all tests are passing with strict types! 👍

Copy link
Collaborator

@MPParsley MPParsley left a comment

Choose a reason for hiding this comment

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

This looks good.

I suppose that for the beta1 release we'll add the following BC breaking change?

from:

  public function isMemberPending(EntityInterface $group, $user_id) {

into:

  public function isMemberPending(EntityInterface $group, int $user) {

@pfrenssen
Copy link
Contributor Author

Thanks for the review! I agree that we can make the change to the int type hint in beta1. I have updated the deprecation check to see if anything other than an integer is passed in, so that people are alerted in time that they need to update their code to pass integers. I also created an issue to handle the removal of the B/C layer: #542 - I mentioned there that we need to update the type hint too.

@pfrenssen
Copy link
Contributor Author

Wow we have a lot of cases where a string is returned from $user->id(), this was quite unexpected. I see that indeed UserInterface::id() is allowed to return strings, even though the ID has been defined as an integer in the base field definitions, and also EntityOwnerInterface::getOwnerId() will always return integers.

I am not sure now about requiring integers, this will be too much of a hassle for developers to always cast to an integer. Let's for now keep the documentation as integer, but not enforce it until core is more strict about its data types. I will remove the strict check on the B/C layer.

The core entity API often returns the user ID as a string value even though it
is defined as an integer in the base field definitions. Let's wait until core
is more strict about returning the right data type.
@pfrenssen pfrenssen merged commit cd4aa73 into 8.x-1.x Jul 23, 2019
@pfrenssen pfrenssen deleted the do-not-require-full-user-object branch July 23, 2019 18:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants