-
Notifications
You must be signed in to change notification settings - Fork 153
Fix parameter type for Assert::isMap()
#331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
`isMap` should accept `mixed` or `array<array-key, T>`, not `array<string, T>`. If the input was `array<string, T>`, we wouldn't need to use `Assert::isMap()`.
|
Isn't |
|
The |
|
I guess it's implementation dependent (the static analysis tool), but yep, agree. |
| * @psalm-assert array<string, T> $array | ||
| * | ||
| * @param array<string, T> $array | ||
| * @param mixed|array<array-key, T> $array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just be mixed. As in, remove the @param declaration because the actual type is already mixed $array.
| * @param array<string, T> $array | ||
| * @param mixed|array<array-key, T> $array | ||
| * | ||
| * @return array<string, T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect, it should be @return array<array-key, T>.
| * | ||
| * @template T | ||
| * | ||
| * @psalm-assert array<string, T> $array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this should be array<array-key, T>.
|
The static analysis tests disagree with all of these points as do I: assert/tests/static-analysis/assert-isMap.php Lines 10 to 38 in a632bc7
|
|
@gsteel the static analysis tests verify expectations of example code, they are not unit tests. The very first line of isMap is The assertion isMap takes a mixed input, proves it is a map (aka associative array), then returns it. |
|
The good thing about the old parameter type The SA tests here backup that perspective. Returning or asserting This patch effectively reverts incorrect changes to this method. If you feel like a map is defined by |
|
Maps can also be |
|
However, I see the message in the assertion is also incorrect in this regard. And I do understand your point about preserving the template value, I'm just not quite sure what to do about it... |
isMapshould acceptmixedorarray<array-key, T>, notarray<string, T>. If the input wasarray<string, T>, we wouldn't need to useAssert::isMap().