beberlei / assert

Thin assertion library for use in libraries and business-model
Other
2.41k stars 188 forks source link

PHPDoc for "all" helper type-hints to "string", disallowing arrays #280

Closed holtkamp closed 4 years ago

holtkamp commented 5 years ago

The documentation for the "all" helper states:

The Assertion::all* method checks if all provided values hold for the assertion. It will throw an exception of the assertion does not hold for one of the values:

And gives an example for an array.

Checking an array of UUIDs works properly but results in a warning from my IDE:

Screenshot 2019-05-28 at 12 42 10

This is caused by this PHPDoc:

https://github.com/beberlei/assert/blob/f812ed00763ffa96264496730b2672c744414e98/lib/Assert/Assertion.php#L108

Funny thing is, this also occurs for other "allXYZ" helpers, for example:

https://github.com/beberlei/assert/blob/f812ed00763ffa96264496730b2672c744414e98/lib/Assert/Assertion.php#L55-L57

So my question: is it correct that the PHPDoc for some "allXYZ" helpers is incorrect? I can come up with a PR when this is confirmed.

rquadling commented 5 years ago

Hmm. Yes. It looks like \MethodDocGenerator::generateMethodDocs needs a small bit of work to add [] to the first parameter typehint.

* @method static bool allAlnum(mixed[] $value, string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric for all values.

rquadling commented 5 years ago

Some work may be needed for those that are arrays (or of a type that can be thought of as an array to start with - check the allCount() method).

holtkamp commented 5 years ago

Hmm. Yes. It looks like \MethodDocGenerator::generateMethodDocs needs a small bit of work

Aah, that part of the documation is generated, nice! So in that case a PR to just change the PHPDoc does not make a lot of sense...

rquadling commented 4 years ago

Apologies for the lack of response ... life!

                if ($prefix === 'all' && strpos($type, 'null') === false && $parameterIndex === 0) {
                    $type = str_replace('|', '[]|', $type).'[]';
                }

Seems to do the trick.

Released in v3.2.5