Problem/Motivation
This META issue is a spin-off from #1792992: Are typed @param / @return part of the documentation gate? where several people voiced the view that all @param and @return directives in docblocks MUST include type hints. However, some stated that it only SHOULD be a suggestion since "core does not follow this standard yet." The focus of this META issue is to add missing type hinting to @param and @return directives throughout all of existing core documentation.
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.
Proposed resolution
Add type hinting for all @param and @return directives in a series of scoped patches.
How to's
How to review patches for this issue:
# This is a one-liner to aid in reviewing patches on this Drupal.org meta issue:
# https://www.drupal.org/node/1800046
# You can use netbeansdrupalcomposed to gather the dependencies, which are phpcs
# and Drupal's Coder module
# https://www.drupal.org/sandbox/mile23/2197899
# Substitute any module path you want in order to check only that module.
# The resulting list will be a bit of gobbledygook in CSV, but will show you whether
# or not the patch you're evaluating successfully removed the errors we're looking for.
phpcs --standard="/path/to/drupal/coder/coder_sniffer/Drupal" --extensions="module/php,inc/php,php" --report-csv path/to/module/ | grep -F $'Missing param\nReturn type missing'
The above one-liner can also be found in this github gist: https://gist.github.com/paul-m/227822ac7723b0e90647
- Look at the type hint documented for each parameter. Make sure the types correspond to the allowed types at http://drupal.org/node/1354#param-return-data-type.
- Make sure all possibilities for the parameter are documented; for example, if the function optionally accepts a NULL value for a string parameter, then it should be documented as string|null.
- Also check the function's callers and string references (linked on api.d.o) and make sure the values being passed to the function are in the datatypes specified.
- Apply the patch to your local repository, and check that no other functions in these files are missing parameter documentation.
- Document what you reviewed and what you found specifically in your review comment.
Comments
Comment #1
jhodgdonOne more note... These patches take a *large* effort for writers, reviewers, and committers if they are done properly. In most (or at least many) cases, you will need to read the entire function code carefully to figure out what the argument and return value types are.
As I've said before, I personally do not think this is worth the effort to do for all of core. And just for the record, I'll just state here that I personally don't want to spend my volunteer Drupal time, as a committer, to doing final review and commit for these patches. I think I can find more valuable ways to spend my Drupal volunteer time, such as adding new features to the API module (for api.drupal.org) or reviewing/committing other patches (I'm already way behind on other clean-up efforts that I personally feel are more worthwhile).
This initiative has been tried before, and no one came up with the level of effort that would be needed to complete the project. I doubt it's available now... Sorry to be discouraging, but I really feel like the effort needed here could be better spent on other initiatives. But that's my bias... if you can come up with people who want to make it happen and are willing to spend the care and time necessary, I certainly won't stand in the way -- just don't assume that I'm making time available myself.
Comment #1.0
lars toomre commentedUpdated the full set of modules in module table.
Comment #1.1
lars toomre commentedAdded sub-issue for the User module. Also added links to patches for bootstrap and common.inc files.
Comment #1.2
lars toomre commentedUpdated issue summary.
Comment #1.3
lars toomre commentedAdded additional sprint meta issues to related issues section.
Comment #1.4
lars toomre commentedUpdated issue summary.
Comment #1.5
lars toomre commentedUpdated issue summary.
Comment #1.6
lars toomre commentedAdded sub-issue for the node module.
Comment #1.7
lars toomre commentedAdded sub-issue #1800774: Add missing type hinting to menu_ui module docblocks for the menu module.
Comment #1.8
lars toomre commentedUpdated issue summary.
Comment #1.9
lars toomre commentedUpdated issue summary.
Comment #1.10
lars toomre commentedAdded sub issue for image module.
Comment #1.11
lars toomre commentedAdded sub issue for Action module.
Comment #1.12
lars toomre commentedUpdated issue summary.
Comment #1.13
lars toomre commentedUpdated issue summary.
Comment #1.14
lars toomre commentedAdded sub-issue for taxonomy module.
Comment #1.15
lars toomre commentedUpdated issue summary.
Comment #1.16
lars toomre commentedAdded sub-issue for Aggregator module.
Comment #1.17
lars toomre commentedUpdated issue summary.
Comment #1.18
lars toomre commentedUpdated issue summary.
Comment #2
traviscarden commented@jhodgdon, I see that the work here is going forward and that, despite your expressed wish not to spend time on it yourself, some of the issues are getting assigned to you. Is that going to be a bother or a distraction to you?
Comment #3
jhodgdonIf the patches have been carefully reviewed and marked RTBC by the reviewer, I can get assigned to commit them.
Comment #4
lars toomre commented@TravisCarden Reviews in the sub-issues are welcome. Most to date deal with adding type hinting to *.api.php files.
Comment #4.0
lars toomre commentedAdded comment sub-issue.
Comment #4.1
lars toomre commentedAdded sub-issue for Config module.
Comment #4.2
lars toomre commentedUpdated issue summary.
Comment #4.3
lars toomre commentedUpdated issue summary.
Comment #4.4
lars toomre commentedUpdated issue summary.
Comment #4.5
lars toomre commentedUpdated issue summary.
Comment #4.6
lars toomre commentedAdded Dblog sub-issue.
Comment #4.7
lars toomre commentedAdded Filter module sub-issue.
Comment #4.8
lars toomre commentedUpdated issue summary.
Comment #4.9
lars toomre commentedAdded sub-issue #1811858 for file module.
Comment #4.10
lars toomre commentedAdded a sub-issue #1811862 for Help module.
Comment #4.11
lars toomre commentedUpdated issue summary.
Comment #4.12
lars toomre commentedUpdated issue summary.
Comment #4.13
lars toomre commentedUpdated issue summary.
Comment #4.14
lars toomre commentedAdded sub-issue #1811888 for the tracker module.
Comment #4.15
lars toomre commentedUpdated issue summary.
Comment #4.16
lars toomre commentedUpdated issue summary.
Comment #4.17
lars toomre commentedUpdated issue summary.
Comment #4.18
lars toomre commentedUpdated issue summary.
Comment #4.19
lars toomre commentedUpdated issue summary.
Comment #4.20
lars toomre commentedUpdated issue summary.
Comment #4.21
lars toomre commentedAdded sub-issue #1816840 for Overlay module.
Comment #4.22
lars toomre commentedAdded sub-issue #1816846 for PHP module.
Comment #4.23
lars toomre commentedUpdated issue summary.
Comment #5
jhodgdonThis issue forgot to have a tag. :)
Comment #6
ro-no-lo commentedIssue Reminder Comment.
Comment #6.0
ro-no-lo commentedUpdated issue summary.
Comment #7
mile23Poll module is no longer in core.
Comment #8
mile23There's no menu module in core... Hijacking the menu issue to be about menu_ui instead.
Comment #9
mile23All child issues are either closed or have patches needing review.
Comment #10
mile23Added info about how to review the patches, available here: https://gist.github.com/paul-m/227822ac7723b0e90647
Comment #11
heddnLet's get a beta eval documented here. Update the issue summary noting if this allowed during the beta.
Comment #12
mile23Bump up to 8.1.x.
Moving all child issues, too.
Comment #13
jhodgdonWhy are these being moved to 8.1.x? There is absolutely no reason why they cannot be committed to 8.0.x, that I'm aware of.
Comment #14
mile23OK.
I thought we were patching for 8.1.x and then cherry picking for 8.0.x, but whatever.
Comment #15
jhodgdonYes, we are patching 8.1 and cherry picking 8.0.
However, the current way to indicate that a given patch is suitable for both is to set the version to 8.0.x. Issues that are set to 8.1.x mean "This is not suitable for 8.0.x", under current procedures.
This is obviously not very sustainable going forward where we'll have multiple versions, and I didn't come up with the scheme, but that is what we are supposed to do for the moment. For what it's worth...
Comment #16
mile23Some of the child issues don't apply both ways, so some will need to be applied to 8.0.x and then need a port to 8.1.x.
Comment #17
jhodgdonAh, right. In those cases, we would want to make the 8.1 patch first, tag the issue as needing a backport to 8.0, and after 8.1 is committed do the backport. This would be similar to how we never patch 7.x unless 8.x already has the fix in place.
Comment #18
mile23The phpcs script I made manages to ignore .inc files. This hasn't been an issue in some modules, others maybe a bigger deal.
Updating issue summary with new phpcs.
Comment #20
mile23We should re-scope these child issues to fix docblocks based on adding phpcs sniffs to
phpcs.xml.dist.Specifically these:
Drupal.Commenting.FunctionComment.MissingParamNameDrupal.Commenting.FunctionComment.MissingParamTypeDrupal.Commenting.FunctionComment.MissingReturnCommentDrupal.Commenting.FunctionComment.MissingReturnTypeComment #23
xjmRemoving some out-of-date info from the summary.
Comment #24
xjmSo in terms of the scoping for these issues, adding type hints is actually a bit different than most coding standards changes. One has to read the code very carefully to determine what the typehint should be. It's even written up as an example at https://www.drupal.org/core/scope#examples. The advice there is:
I'm not entirely sure about "@return docs entirely separately once the @param docs are known to be correct (since the inputs will affect the outputs)" since when you're reading a method you're probably going to figure out both.
The advice for documentation patches generally is:
So, my recommendation for issue scoping:
Drupal.Commenting.FunctionComment.MissingParamNamethroughout core. That one can be automated.Drupal.Commenting.FunctionComment.MissingParamTypeandDrupal.Commenting.FunctionComment.MissingReturnType. Document the violations here.Drupal.Commenting.FunctionComment.MissingReturnComment, again scoping them as documentation patches.Comment #30
quietone commentedMoved the work from the child patches to #3207949: Fix Drupal.Commenting.FunctionComment.MissingParamType. When applying the patches I found only one or two changes to @return the rest were to @param statements.
Comment #31
quietone commentedThanks for the work done here!
The community has decided that the best way to approach this is by fixing a rule at a time, rather than a file at a time. See #2571965: [meta] Fix PHP coding standards in core, stage 1 for the meta issue where this effort is being organized, The FunctionComment work is in #2572645: [Meta] Fix 'Drupal.Commenting.FunctionComment' coding standard.
Closing this as a duplicate