Coding-standard: TypeHintDeclarationSniff does not consider array of arrays

Created on 10 Nov 2018  路  8Comments  路  Source: slevomat/coding-standard

The inspection reports the absence of type hint in the return and parameter of a method if the type is an array of arrays (array[]).

/**
 * @param array[] $arrays
 *
 * @return array[]
 */
public function getAdditionTests(array $arrays) : array
{
    return [
        '1 + 2 = 3' => [
            'augend' => 1,
            'addend' => 2,
            'result' => 3,
        ],
    ];
}

The above snippet produces the following non-applicable warning:

@param annotation of getAdditionTests() does not specify type hint for items of its traversable parameter $arrays.
@return annotation of getAdditionTests() does not have @return annotation for its traversable return value.
Invalid

Most helpful comment

@kukulich you could be more open to bug reports, as we spend time reporting an issue not only because it affects us, but also to help make the library more robust. This is the second issue you closed providing no feedback about the problem reported. _Closing an issue does not fix it._

The annotation @param array[] is a perfect valid PHPDoc annotation, that implies an array of arrays of mixed values. Why should I replace such a simple notation for something much less clear like mixed[][]? What is invalid in my complaint?

All 8 comments

You should use mixed[][] or something like this.

You should use mixed[][] or something like this.

Why?

@kukulich you could be more open to bug reports, as we spend time reporting an issue not only because it affects us, but also to help make the library more robust. This is the second issue you closed providing no feedback about the problem reported. _Closing an issue does not fix it._

The annotation @param array[] is a perfect valid PHPDoc annotation, that implies an array of arrays of mixed values. Why should I replace such a simple notation for something much less clear like mixed[][]? What is invalid in my complaint?

@lookyman @marcospassos

The reported error is about specifying type of the items of the array. array is not valid type because it doesn't say anything about the type. It is just useless.

But I'm doing exactly it: array is the type of the items. What is wrong with having an array of tuples, for instance?

/** @param array[] $arrays */
function foo() : array {
    return [[1, 2], [3, 4]];
}

Besides this, if mixed[][] is valid, it implies thatarray[] should work as well, as it means an array of arrays containing mixed values.

No, array is not valid in this sniff, deal with it :)

@kukulich I will deal with it (have been doing that since I started using this cs), but I still don't understand your reasoning.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings