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 Tracker 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 |
|---|---|---|---|
| #14 | add-missing-type-hinting-tracker-1811888-14.patch | 2 KB | naveenvalecha |
| #12 | add-missing-type-hinting-tracker-1811888-12.patch | 2.83 KB | a_thakur |
| #10 | add_missing_type-1811888-10.patch | 1.88 KB | nitesh sethia |
| #9 | 1811888_9.patch | 1.95 KB | mile23 |
| #4 | 1811888.patch | 3.46 KB | bleen |
Comments
Comment #1
bleen commentedComment #2
lars toomre commentedSetting the status so we can see what the bot thinks...
Comment #3
lars toomre commented@bleen18 Here is a detailed review of the patch in #1.
I could easily make the needed changes myself, but if I update the patch, I will not be able to RTBC it for @jhodgdon. Perhaps you can incorporate the needed changes from below? Thanks in advance.
After applying this patch locally, I grepped through all of the Tracker module and confirm that with these type hinting additions, this module would have complete type hinting coverage.
This change to _tracker_myrecent_access() docblock is correct.
This change to _tracker_user_access() docblock is also correct.
Each of these three changes to the docblock for _tracker_add() are correct.
This change in docblock for _tracker_calculate_changed() is correct.
The indentation for this portion of the docblock is incorrect. (Needs to be in one more space.)
However, the added type hint of int is correct.
The type hints added for _tracker_remove() are all correct. I also confirmed that there is no @return directive required.
One thing that does need to be done for this docblock is to add '(optional)' at the start of the optonal variables and to explicitly state what their default values are with 'Defaults to NULL.'
The docblock for tracker_page() needs to be changed.
The first @param directive should be 'obj|null' and the phrase 'Defaults to NULL.' needs to be added to the end of its explanation.
The type hint for the second @param is correct. However, the explanation needs to start with '(optional)' and it also needs to state what the default value is.
Comment #4
bleen commentedThis patch address all the issues in #3 (and one or two other indent problems) except for including obj|null in the very last docblock. That would be the only place where we list NULL as a possible value for an optional parameter... even the docblock immediately before this one would need that listed, no?
Comment #5
lars toomre commentedThanks for the patch @bleen18! This time I figured out from looking at the Test results what the exact patch file name was. Previously, I did not know to look there.
This is another nit pickity review of the patch so that we arrive at something that is pristine when it gets to RTBC stage:
Thanks for the change from 'boolean' to 'bool'. With patch applied, I can confirm that all of these type of changes are correct and that there are no more 'boolean' type hints in this patch.
These added type hints are all correct.
Reading the description for $changed, I think that could be clarified as it confused me at first. Perhaps something like 'A timestamp value, from when either a comment was added, or the last time the node was updated.'? What do you think?
These type hints for _tracker_calculate_changed() are correct.
My understanding in _tracker_remove() is that the second two of the added type hints here both need to be 'int|null'. Is that what was being referred to in #4? I note that my review from #3 was incorrect for this docblock.
My understanding is that this sort of type hint should be spelled out as 'object'. In addition, for this docblock, the correct type hint should properly be 'object|null'.
The second added type hint here is correct.
====== Other observations from reading through the Tracker files with this patch applied:
1) I wonder whether we should file a new issue to add type hinting in the function declaration in functions like tracker_comment_update($comment). I would think that at minimum it should be 'object $comment' if not 'Comment $comment'. What do you think?
2) We did not add the type hint for $account in this patch for either _tracker_myrecent_access() or _tracker_user_access(). However, reading both functions I believe that both type hints are incorrect.
The first function is clearly referencing $account as an object. Hence, I believe that $account type hint should be 'object'.
The second $account variable is used in the call to user_view_access() where it can be either an integer or an object. Hence, the second type hint should properly be 'int|object'.
3) Finally, with this patch applied locally, I can confirm that we have caught all of the type hinting for @param and @return directives in the Tracker module.
Thanks again for this patch @bleen18. As I stated in other sub-issue for this initiative, I could roll a patch that incorporates these review issues. However, if I do so, my understanding is that neither you nor I could then elevate the result to RTBC. Hence, I would like to keep myself at the review status for this issue so that we can generate a pristine patch that is ready for final review and commit. Again @bleen18, thanks for your help in getting us there!
Comment #6
mile23Comment #7
mile23Comment #8
mile23Comment #9
mile23I couldn't make the reroll work for some reason, so I re-did the changes manually. There are only a few, and
tracker.pages.incno longer has the docblock we're fixing.I had to change hinting from int for user id to AccountInterface.
Our handy-dandy phpcs one-liner says all is well. https://gist.github.com/paul-m/227822ac7723b0e90647
Comment #10
nitesh sethia commentedRerolled the patch as per the latest release.
Comment #11
a_thakur commentedApplied the latest patch. The patch applies cleanly. But we do see some docblocks which need fix, these are basically test files.
For example src/Tests/TrackerTest.php:435: type is missing. Can we clean these as well?
Comment #12
a_thakur commentedPlease find a new patch which fixes the missing type hinting in test files as well.
Comment #13
mile23Bumping up to 8.1.x. Patch no longer applies.
Comment #14
naveenvalechanothing returntype/param missing error
Admins-MacBook-Pro% phpcs --standard="Drupal" --extensions="module/php,php" --report-csv core/modules/tracker | grep -F $'Missing param\nReturn type missing'Comment #15
mile23Cool, thanks.
The patch applies, phpcs says no problems, hints look correct.
Comment #16
jhodgdonI see no reason this cannot be committed to 8.0.x as well -- it is a straightforward documentation change. I also second the RTBC status.
Comment #18
jhodgdontestbot glitch
Comment #19
mile23Retesting after testbot glitch.
Comment #22
catchCommitted/pushed to 8.1.x and cherry-picked to 8.0.x, thanks!