2

Is there a phpdoc-compliant way* of expressing the various returned values in a PHPUnit dataProvider?

For example:

return array(
    array(false, 17, array(1,2)),
    array(true, 19, array(1,2)),
);

I would like to write something more detailed than @return array, that expresses that the first value passed to the test method is a bool, the second is an integer, third is an array (and also what each of these values represent).

* If there's no compliant way, does anyone have tips on how to document in a clear manner?

1 Answer 1

1

The only further specification for arrays is what they contain (if always the same type):

/**
 * @return array[]
 */
function() {
    // ...
}

This annotation expresses the function will return an array of arrays, you can find a further discussion in this question:

PHPDoc type hinting for array of objects?

Note: Not every IDE will be able to interpret it

To a possible clear manner: In my opinion, you can always use code blocks in your comments to explain some of your code:

/**
 * returns array with following structure:
 * <code>
 * array(
 *     array(
 *         (bool), (int), (array)
 *     )
 * )
 * </code>
 *
 * @return array[]
 */

Or similar explanation. I'm sure there are plenty ways to give other developers a hint about what to expect. In the end it just needs to be understandable to a human if it is not included in the usual annotations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.