Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is a sub-issue of #1800046: [META] Add missing type hinting to core docblocks, fix Drupal.Commenting.FunctionComment.Missing* focused on correctly adding @param and @return type hinting to the User module.
Documentation patches that include type hinting are time consuming to both review and commit because one must dig into the actual code to confirm that the type hints are both correct and complete. Hence, please be patient and try to limit type hint patches to covering only a limited number of docblocks (10-15 as a guess).
How To Review This Issue
- Attempt to apply the patch to see if it needs a reroll.
- Use the phpcs one-liner to evaluate whether all the relevant standards errors have been resolved: https://gist.github.com/paul-m/227822ac7723b0e90647
- Look at each change and determine whether the type hint is correct.
Related sprint issues:
Comment | File | Size | Author |
---|---|---|---|
#31 | interdiff--1800174-#27-#31.txt | 1.32 KB | rishikant05 |
#31 | add-missing-type-hinting-to-user-module-docblocks-1800174-#31.patch | 16.32 KB | rishikant05 |
#27 | interdiff.txt | 2.04 KB | Mile23 |
#27 | 1800174_27.patch | 17.27 KB | Mile23 |
#21 | interdiff.txt | 3.7 KB | Mile23 |
Comments
Comment #1
Lars Toomre CreditAttribution: Lars Toomre commentedThe first patch in this sub-issue addresses type hinting for approximately a dozen functions in the user.module file.
As this is a module that dates from Drupal's earliest days, this one file will require several iterations before it fully contains accurate and complete docblocks that include type hinting on all appropriate @param and @return directives. At present, there are more than a half-dozen functions in this one file that have no docblock whatsoever.
Comment #2
Lars Toomre CreditAttribution: Lars Toomre commentedZero bytes... Grr!! Let try that attachment again!
Comment #2.0
Lars Toomre CreditAttribution: Lars Toomre commentedAdded reference to relevent API docs issue.
Comment #2.1
Lars Toomre CreditAttribution: Lars Toomre commentedAdded reference to Code Review sprint issue.
Comment #2.2
Lars Toomre CreditAttribution: Lars Toomre commentedReformatted related issues as a table.
Comment #2.3
Lars Toomre CreditAttribution: Lars Toomre commentedAdded links to Meta issues.
Comment #3
Lars Toomre CreditAttribution: Lars Toomre commentedHere is a patch that adds missing type hinting to all @param and @return directives in hook declarations in user.api.php file.
Where appropriate, I also added missing array hinting to parameters in the function declarations as well.
Comment #3.0
Lars Toomre CreditAttribution: Lars Toomre commentedCorrected table labels.
Comment #4
Jalandhar CreditAttribution: Jalandhar commentedPatch no longer applies. It needs reroll.
Comment #5
Jalandhar CreditAttribution: Jalandhar commentedHere is the updated patch
Comment #6
Mile23Comment #7
idebr CreditAttribution: idebr commented$account is now typehinted by its interface, for example see http://cgit.drupalcode.org/drupal/tree/core/modules/user/src/Permissions...
Comment #8
Mile23More work. I think I got most.
Ended up filing this issue, because there was a big @todo about refactoring with no associated issue: #2403729: Convert user_cancel_confirm() to a new-style Form object
Comment #9
dawehnerIs this really a menu callback? Isn't that a controller?
Its Drupal\user\Entity\User now.
Why can't we typehint for \Drupal\user\UserInterface here?
Comment #10
idebr CreditAttribution: idebr commentedYes, $account should be type hinted by its interface, I commented on it earlier in #7.
Comment #11
Mile23Thanks for the review.
#9.1: I just copied the docblock over from user_cancel_confirm(), and I guess I should remove that change from this patch.
#9.2: Well spotted, but I'll go you one better. The first thing this function does is this:
Which means it has to be
AccountInterface
, although there is that weirdness withelseif (!empty($account->homepage)) {
.#9.3:
user_delete_multiple()
just callsentity_delete_multiple()
, anduser_view()
just callsentity_view()
. Both take anEntityInterface
. There's really no difference between theuser_
andentity_
methods in this regard, since entities are so well encapsulated.In fact, there should be a
static EntityInterface::deleteMultiple($entities[]);
but that's a whole other scope.Regardless.. I'll change it all.
I added actual type hinting in user.module. if that explodes, then a) there's a new issue to file, and b), I'll take it out and restrict my changes to only docblocks.
Comment #12
dawehnerThank you for taking the review into account.
Comment #13
alexpottNeeds reroll
Comment #14
Mile23Reroll.
Comment #15
YesCT CreditAttribution: YesCT commentedactual tag has no dash.
Comment #16
Mile23Doesn't need a reroll, needs review. :-)
Comment #17
idebr CreditAttribution: idebr commentedActually it did need a reroll :)
Changes look good! Let's get this in.
Comment #18
idebr CreditAttribution: idebr commentedTestbot came back green, settings to RTBC.
Comment #19
YesCT CreditAttribution: YesCT commentedtook out some unrelated changes that were out of scope of the issue.
added the leading \ to namespaces https://www.drupal.org/node/1353118
added some types to function definition to match the types added to the @param's
lowercase null should be used for types in @param and @return
https://www.drupal.org/node/1354#types
why this change?
It is false that it is an associative array with the role id as the key?
why the change in the description? looks like it is returning an array of objects, not strings.
Can we do
\Drupal\user\EntityOwnerInterface[]
?
relevant...
$roles = Role::loadMultiple();
maybe it should be
\Drupal\user\RoleInterface[]
Comment #20
Mile23Needed a reroll.
#19.1: You got the nulls...
#19.2 and #19.3: Setting the
@return
comments to be the same as api.drupal.org.Also in #19.3: Let's just say
RoleInterface[]
. The entity system doesn't enforce it, but it just so happens thatRole
implementsRoleInterface
, and the interface is where we want people to go for documentation.Comment #21
Mile23Here it is again without changing the function signatures. This way it can be evaluated as a documentation change.
Comment #22
idebr CreditAttribution: idebr commentedThe patch in #21 removes the type hinting from the function signatures, so the feedback has been addressed or no longer applies since the patch updates the documentation only.
Comment #23
jhodgdonUm, really?
User object is a stdObject object, not a particular class? (occurs multiple times in this patch). Shouldn't it be:
like in other spots in the patch?
Also, if you're fixing a function first line, like here:
Might as well also change Retrieve to Retrieves?
Also this is missing the \ in user.module:
I stopped reading the patch here but it's not really ready.
Comment #24
jhodgdonAlso, PLEASE do not set this or any of the other related issues to RTBC until the patch has been ***carefully*** reviewed and verified to be correct.
Comment #25
idebr CreditAttribution: idebr commentedMy bad, I'll leave this for the documentation team :)My bad, I'll try to get the documentation right next time instead of checking if the patch applies.
Comment #26
jhodgdonThere is no "documentation team".
What we have is hopefully a community of Drupal developers who try to get the code documentation right. All I'm asking is that before marking a patch that is supposed to be fixing the documentation as "reviewed and tested", that the documentation actually be reviewed for accuracy, not just that the patch applies.
Comment #27
Mile23@idebr: Thanks for working on it, at least.
@jhodgdon: Thanks for the mini-review. This patch addresses everything you mention, and also some stale docs in
user_user_logout()
.Comment #28
Mile23Still applies, still addresses all missing hinting in docblocks.
Comment #29
Mile23Comment #30
rishikant05 CreditAttribution: rishikant05 commentedComment #31
rishikant05 CreditAttribution: rishikant05 at Srijan | A Material+ Company commentedRerolling the patch as its not applied.
Comment #32
rishikant05 CreditAttribution: rishikant05 at Srijan | A Material+ Company commentedComment #33
yogen.prasad CreditAttribution: yogen.prasad commentedLooking Fine
Comment #34
webchickLooks like all previous feedback has been addressed.
Committed and pushed to 8.0.x. Thanks!