Download & Extend

Add missing @param in includes A-C, plus other corrections to some docblocks

Project:Drupal core
Version:8.x-dev
Component:documentation
Category:task
Priority:normal
Assigned:Unassigned
Status:needs review
Issue tags:docs-cleanup-2011

Issue Summary

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

#1

Status:postponed» active

Setting active since #1315886: Clean up API docs for includes directory, files starting with A-C is closed.

#2

Title:Add missing @param in includes A-C» Add missing @param in includes A-C, plus other corrections to some docblocks

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.
AttachmentSizeStatusTest resultOperations
bootstrap-common-params.patch11.21 KBIdlePASSED: [[SimpleTest]]: [MySQL] 35,359 pass(es).View details | Re-test

#3

Status:active» needs review

#4

+++ 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.

#5

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!

#6

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.

#7

Assigned to:xjm» August1914

Reviewing

#8

Assigned to:August1914» Anonymous

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.

#9

Assigned to:Anonymous» tim.plunkett

I'm checking step 10.

#10

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.

#11

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.:

<?php
// 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?

#12

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").

#13

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.

#14

Assigned to:tim.plunkett» Anonymous

#15

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.

AttachmentSizeStatusTest resultOperations
1326456-15-docs-A-C.patch14.13 KBIdlePASSED: [[SimpleTest]]: [MySQL] 41,902 pass(es).View details | Re-test

#16

Status:needs work» needs review

Helps if I change the status!

#17

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!

#18

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.

#19

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.

#20

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".

#21

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.

#22

Status:needs work» needs review

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.

AttachmentSizeStatusTest resultOperations
1326456-22-docs-A-C.patch26.27 KBIdlePASSED: [[SimpleTest]]: [MySQL] 42,805 pass(es).View details | Re-test
interdiff-1326456-15-22.txt15.18 KBIgnoredNoneNone
nobody click here