Problem/Motivation

From #1315886: Clean up API docs for includes directory, files starting with A-C. There are undocumented parameters in the following files:

  • bootstrap.inc
  • common.inc

Proposed resolution

Add documentation for all parameters in these files.

Remaining tasks

Followup issues

Miscellaneous

Comments

NROTC_Webmaster’s picture

Status: Postponed » Active
xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

.

xjm’s picture

Title: Add missing @param in includes A-C » Add missing @param in includes A-C, plus other corrections to some docblocks
StatusFileSize
new11.21 KB

Attached adds parameter documentation for all functions in bootstrap.inc and common.inc that were missing it. Few notes:

  • I added datatypes, since the patch requires looking up what the parameters were anyway.
  • drupal_json_encode() is legitimately mixed; it can accept any PHP datatype.
  • I corrected the parameter for a couple of Render API callback where the parameter was mispelled ($element rather than the $elements that actually appears in the function signature and is used in the function.)
  • I also made a few other incidental corrections that were revealed by writing the parameter documentation for these functions, e.g. wonky return value documentation, undocumented callbacks, and misleading function summaries.
xjm’s picture

Status: Active » Needs review
NROTC_Webmaster’s picture

+++ b/core/includes/common.incundefined
@@ -3316,7 +3352,7 @@ function drupal_aggregate_css(&$css_groups) {
+ * @param array $elements
  *   A render array containing:
  *   - '#items': The CSS items as returned by drupal_add_css() and altered by
  *     drupal_get_css().

Did you leave the single quotes in intentionally? I'm just not sure how many incidental things you were trying to catch in this one.

xjm’s picture

The scope is only what is indicated in the summary and title. There's a separate issue for the list cleanups (#1333534: Further cleanup for documentation in core/includes files starting with A-G ), and it's very important to me to keep these tasks separate because these particular files are so large and so full of legacy stuff that they patches would be impossible to review otherwise. :)

Thanks for checking though!

xjm’s picture

To review this patch:

  1. Review only the changed lines (lines with a + or - in front of them, not the other lines which are provided for context.)
  2. Check that each parameter block is formatted correctly per http://drupal.org/node/1354#functions, including the correct indentation and the correct whitespace between the parameter list and other parts of the docblock.
  3. Check that the parameters are identified correctly. For example, if the function signature is function_name($foo_bar), the parameter should be listed as $foo_bar in the docblock, not $foobar.
  4. Check that all parameters are documented, unless our standards explicitly specify omitting them (as with form constructors).
  5. Check that the parameters are in the order specified in the function signature.
  6. Read each parameter description and make sure that it is grammatically correct, clear English, with proper capitalization, punctuation, etc. (Each parameter description should form a complete English sentence if the words "This parameter is..." were to be added to the beginning, but those words should not be included in the docblock.) Keep an eye out for typos.
  7. Look up each function in the patch on api.drupal.org (D8). Read the function carefully and ensure that the parameter description properly documents how the parameter is used.
  8. Look at the datatype documented for each parameter. Make sure the types correspond to the allowed types at http://drupal.org/node/1354#param-return-data-type.
  9. 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.
  10. 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.
  11. Apply the patch to your local repository, and check that no other functions in these files are missing parameter documentation.
  12. Document what you reviewed and what you found specifically in your review comment.
August1914’s picture

Assigned: xjm » August1914

Reviewing

August1914’s picture

Assigned: August1914 » Unassigned

Reviewed for steps 1-9, and I think everything checks out.
Step 10 references I think hundreds of calls, so that is still pending.
Applied the patch to drupal-8.x-dev, and verified that all params are documented.

Apart from the unverified callers and string references, looks good.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

I'm checking step 10.

tim.plunkett’s picture

Status: Needs review » Needs work
+++ b/core/includes/bootstrap.incundefined
@@ -1923,6 +1941,12 @@ function drupal_array_merge_deep() {
+ * @param ...
+ *   Arrays to merge.

This should be @param array $arrays

+++ b/core/includes/common.incundefined
@@ -2055,6 +2087,10 @@ function date_iso8601($date) {
  * Translates a formatted date string.
  *
  * Callback for preg_replace_callback() within format_date().
+ *
+ * @param string|null $new_langcode
+ *   (optional) The language code to used for translation. Cached statically.
+ *   This parameter is ignored if $matches is passed.
  */
 function _format_date_callback(array $matches = NULL, $new_langcode = NULL) {
   // We cache translations to avoid redundant and rather costly calls to t().

Missing @param array $matches, or maybe array|null? The data type in the function signature directly conflicts with the default, that's weird.

+++ b/core/includes/common.incundefined
@@ -3582,6 +3618,14 @@ function drupal_build_css_cache($css) {
 /**
  * Prefixes all paths within a CSS file for drupal_build_css_cache().
+ *
+ * Callback for preg_replace_callback() within:
+ * - drupal_build_css_cache()
+ * - color_scheme_form_submit()
+ *
+ * @param string|null $base
+ *   (optional) The base path for the CSS files. Cached statically. This
+ *   parameter is not used if $matches is passed.
  */
 function _drupal_build_css_path($matches, $base = NULL) {
   $_base = &drupal_static(__FUNCTION__);
@@ -3716,8 +3760,10 @@ function drupal_load_stylesheet_content($contents, $optimize = FALSE) {

@@ -3716,8 +3760,10 @@ function drupal_load_stylesheet_content($contents, $optimize = FALSE) {
 /**
  * Loads stylesheets recursively and returns contents with corrected paths.
  *
- * This function is used for recursive loading of stylesheets and
- * returns the stylesheet content with all url() paths corrected.
+ * Callback for preg_replace_callback() in drupal_load_stylesheet_content().
+ *
+ * This function is used for recursive loading of stylesheets and returns the
+ * stylesheet content with all url() paths corrected.
  */
 function _drupal_load_stylesheet($matches) {

Also missing $matches

+++ b/core/includes/common.incundefined
@@ -6465,6 +6523,9 @@ function element_property($key) {
  * Gets properties of a structured array element (keys beginning with '#').
+ *
+ * @param array $element
+ *   The structured array to filter.
  */
 function element_properties($element) {
   return array_filter(array_keys((array) $element), 'element_property');

Weird that this casts it to an array.

The rest looks fine.

xjm’s picture

This should be @param array $arrays

I don't think this is correct. See drupal_array_merge_deep(). It's not an array of arrays as one parameter; it's a non-fixed number of array parameters passed to the function and retrieved with func_get_args(). E.g.:

// Could be:
$foo = bar($array1);

// Or:
$foo = bar($array1, $array2);

// Or:
$foo = bar($array1, $array2, $array3, $array4, $array5, $array6, $array7, $array8, $array9, $array10);
Missing @param array $matches, or maybe array|null? The data type in the function signature directly conflicts with the default, that's weird.
...
Also missing $matches

I omitted this because it's a preg_replace callback, which takes $matches as the first parameter without $matches being passed by the actual calling code. (PHP creates and passes this parameter internally.) See http://us.php.net/preg_replace_callback under the description of the callback parameter, and also see how these are used in (e.g.) drupal_build_css_cache().

When we originally set the callback standards, we talked about omitting parameter descriptions that were always the same like we do for hook implementations and Drupal-specific callbacks, although it looks like this didn't make it into 1354 explicitly. Do you think that's unclear here? Maybe it needs to be something like:
The matches found for the regular expression passed to preg_replace_callback() with this callback. See preg_match() for more information.

Weird that this casts it to an array.

Yeah, that seems... wrong. I checked and core only calls it once, in filter_process_format(), which is only used as the #process callback for filter_element_info(). Maybe we should remove the typecast in D8, as I don't see how an object should ever get passed there?

xjm’s picture

Oh, regarding:

The data type in the function signature directly conflicts with the default, that's weird.

Yeah, I thought that was code smell too. I have it on a list of followup issues to file (summary under "miscellaneous").

tim.plunkett’s picture

That's true of drupal_array_merge_deep(), but this docblock is for drupal_array_merge_deep_array(), which actually does take an array of arrays.

It just looks like its for the other one because of dreditor's context.

About the callback stuff, that's fine. As long as it makes it into 1354.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
lars toomre’s picture

StatusFileSize
new14.13 KB

Attached is an updated patch for this issue.

This patch includes what I understood from all of the intervening comments. In addition, only for those docblocks in which @xjm added a type hinting @param, I added type hinting to all other @param and @return directives in that docblock (as I thought appropriate).

My reasoning was that if reviewers and committers had to check one type hint, let's do that whole docblock in one go. It will ease the burden of getting type hinting committed. As a result, there were several missing @return directives that I added just to those docblocks @xjm had touched.

The instructions from #6 still apply in reviewing this patch.

Edit: Interdiff was same as patch. Not sure what to I did there.

lars toomre’s picture

Status: Needs work » Needs review

Helps if I change the status!

jhodgdon’s picture

This patch is too substantial for me to want to review/commit all in one go with no other oversight. Can someone else please give it a thorough review for content/correctness? Thanks!

lars toomre’s picture

It would be great if we could get someone (other than @jhodgdon) to review the patch in #15. I was reviewing bootstrap.inc in another issue and noticed a couple of missing @param directives that this patch adds. It would help both bootstrap.inc and common.inc to get this committed soon. Thanks.

cameron tod’s picture

An issue which overlaps with this one came up in the core queue: #1816008: drupal_cron_run() @return parameter documentation incorrect, should specify returns TRUE or FALSE

I have posted a patch there, if it is RTBC I guess we should probably incorporate it here.

cameron tod’s picture

Status: Needs review » Needs work

This patch looks really great and clean! Very small things I noticed:

+++ b/core/includes/bootstrap.incundefined
@@ -953,6 +956,15 @@ function drupal_get_filename($type, $name, $filename = NULL) {
+ *
+ * @return array
+ *   An associative array of variable keys and  values.

Looks like there are two spaces before "values."

+++ b/core/includes/bootstrap.incundefined
@@ -1221,6 +1233,9 @@ function drupal_get_http_header($name = NULL) {
+ * @param string|null $name
+ *   (optional) An HTTP header name. Defaults to NULL.

The string|null notation confused me so I checked node/1354 - great to see this has been adopted for 8!

+++ b/core/includes/common.incundefined
@@ -6686,7 +6782,14 @@ function watchdog_severity_levels() {
+ * @return array
+ *   An emty array or an array of strings.

Typo on "emty".

lars toomre’s picture

Attached are the results of a self-review after letting this sit for several weeks. A patch is forthcoming that will incorporate this and all other comments back to #15.

+++ b/core/includes/bootstrap.incundefined
@@ -459,16 +459,16 @@ function conf_path($require_settings = TRUE, $reset = FALSE) {
+ * @param string $http_host
  *   The hostname and optional port number, e.g. "www.example.com" or
  *   "www.example.com:8080".

Should be 'e.g.,'

+++ b/core/includes/bootstrap.incundefined
@@ -459,16 +459,16 @@ function conf_path($require_settings = TRUE, $reset = FALSE) {
+ * @param bool $require_settings
+ *   (optional) Boolean indicating whether to recognize only configuration
+ *   directories with an existing settings.php file. Defaults to TRUE.

Should be 'A Boolean'

+++ b/core/includes/common.incundefined
@@ -2017,6 +2055,17 @@ function date_iso8601($date) {
+ * @param string|null $new_langcode
+ *   (optional) The language code to used for translation. Cached statically.
+ *   This parameter is ignored if $matches is passed.

Need to add 'Defaults to NULL.'

+++ b/core/includes/common.incundefined
@@ -3253,6 +3302,21 @@ function drupal_build_css_cache($css) {
+ * @param string|null $base
+ *   (optional) The base path for the CSS files. Cached statically. This
+ *   parameter is not used if $matches is passed.

Needs to add 'Defaults to NULL.'

+++ b/core/includes/common.incundefined
@@ -4665,6 +4731,7 @@ function drupal_get_library($module, $name = NULL) {
  * @param $limit
  *   (optional) Limit the maximum amount of parenting in this table.

Needs to specify what the default value is.

lars toomre’s picture

Status: Needs work » Needs review
StatusFileSize
new15.18 KB
new26.27 KB

The attached patch is untested locally. An interdiff with the patch from #15 is also attached.

This patch includes all of the noted issues through #21. It also includes the fix from #1816008: drupal_cron_run() @return parameter documentation incorrect, should specify returns TRUE or FALSE.

While re-rolling the patch, I noticed a few docblocks were missing the '(optional)' explanation start string. Hence, I included that here too. Also, in correcting the first point from #21, I went through both bootstrap.inc and common.inc and corrected all other incorrect uses of 'e.g.' followed by a space. The correct use is 'e.g.,' as I understand.

Once this issue gets committed, I would recommend that we do a thorough review of both bootstrap.inc and common.inc probably as separate follow-up issues (since both are so big and have lots of legacy functions). There still is stuff to do in both to bring them up to D8 documentation standards.

lars toomre’s picture

Issue summary: View changes

.

areke’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

Argh, it looks like this should be re-rolled again.

tim.plunkett’s picture

+++ b/core/includes/bootstrap.inc
@@ -411,13 +411,13 @@ function timer_stop($name) {
- *   Only configuration directories with an existing settings.php file
- *   will be recognized. Defaults to TRUE. During initial installation,
- *   this is set to FALSE so that Drupal can detect a matching directory,
- *   then create a new settings.php file in it.
+ *   (optional) Only configuration directories with an existing settings.php
+ *   file will be recognized. Defaults to TRUE. During initial installation,
+ *   this is set to FALSE so that Drupal can detect a matching directory, then
+ *   create a new settings.php file in it.

It's hard to keep this from needing rerolls when the issue is about adding missing @param, but instead the patch touches almost every docblock.

jhodgdon’s picture

Status: Needs work » Closed (won't fix)

Most of the "cleanup" issues have been marked "won't fix" at this point, as they're so hard to get right, review, and commit, for little benefit.

I am inclined to do the same with this one.

If someone is passionate about adding just the missing @param statements and wants to roll a *small* patch that just does that, maybe we could get it in (go ahead and reopen if you want), but for now I'd say let's not bother.

donquixote’s picture

Status: Closed (won't fix) » Active

I am working on this, but I need to post a rant before I post yet another patch.
(after 2x of posting the wrong patch in the wrong issue, see [#8543447-21] and [#8543307-1])
@jhodgdon: I am happy to do this on IRC. Just don't see you online atm.

Producing the code changes mentioned above was really easy. But then jumping from one issue to the next to find the correct place, and then having to disect the patch to only commit those parts that fit into a specific issue is demotivating and time-consuming.
I suspect this is part of the reason why this is still not fixed after years, and that we are losing a lot of potentially valuable "casual" contributions from people who are angry at the code style in a specific file, want to fix it and move on.

This being said, i agree with tim.plunkett in #24 that we should focus on stuff that is straightforward and easy to review. Like just adding @param or @return. But slowing it down to match the exact scope of an issue that has been idle for years sounds like quite unproductive to me.

We don't need to close an issue once a piecemeal patch has landed. We can just leave it open, and the next person has less work to do.

(this is tim.plunkett's quote)

It's hard to keep this from needing rerolls when the issue is about adding missing @param, but instead the patch touches almost every docblock.

This was the rant, next comes a patch. git add -p is awesome.

donquixote’s picture

Important questions, before I post the patch:
- Does @see go after the @param and @return, or before it?
- Does @throws go before @return or after? phpstorm puts it before.

https://drupal.org/coding-standards/docs#throws does not really address these questions of order for @see and @throws. And looking at existing code does not guarantee the right answers.

And another question:
Is this just about missing @param, or do we also add missing type declarations on existing @param tags?
And for those @param tags we add, do we add docblock text? Or just the empty tag?
Imo, it would be easier to commit the empty tags and then continue from there by leaving the issue open. This will be a lot easier to review in the first step, and means less rerolling.

Also, I am going to leave out anything where I don't know the exact type. This again should help to speed up the review process and reduce the number of rerolls.

donquixote’s picture

I found the answer about the order question :)
https://drupal.org/node/1354#order (don't know how I missed that)

donquixote’s picture

I talked with jhodgdon on IRC.
The conclusion:
This family of issues should remain closed, because it is an approach that failed. This does exactly confirm the concerns I expressed above.
Instead, issues like #2210565: Docblock and code style improvements in core/includes/bootstrap.inc are exactly the way to go. So I am going to re-open that!

jhodgdon’s picture

Status: Active » Closed (won't fix)

OK then, closing this issue back up.

mile23’s picture