-
Notifications
You must be signed in to change notification settings - Fork 529
Use named argument in error for variadic types #3611
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
Conversation
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.
- Rebase this on top of 2.0.x
- I'd much rather do it in
describeParameter
private method, but please rethink how the message (messages) should change.
You have about 48 hours to do this change, otherwise we'd have to put it behind bleeding edge :)
I can do that, but let's first agree on the error message: -Parameter ...$args of method NamedArgumentsMethod\Foo::doIpsum() expects string, int given.
+Named argument foo for parameter ...$args of method NamedArgumentsMethod\Foo::doIpsum() expects string, int given. ? |
What about |
(Only add "variadic" before parameter only for this specific message, not always.) |
93e808d
to
991773b
Compare
Updated the PR
Seeing this, I don't think it's what you had in mind. How to deal with this when I need to do this in Introduce a 3rd nullable argument and only set it for |
991773b
to
292ee14
Compare
No, the point for doing it in The current version is wrong for non-variadic parameters. |
Could you tell me what's wrong? I'm lost now. |
292ee14
to
34570b7
Compare
if (is_int($positionOrNamed)) {
$parts[] = 'Parameter #' . $positionOrNamed;
} elseif (is_string($positionOrNamed)) {
$parts[] = 'Named argument ' . $positionOrNamed . ' for variadic parameter';
} else {
$parts[] = 'Parameter';
} The For example: |
Wow, that doesn't make any sense at all indeed. |
When a type is variadic, and multiple named arguments are used, it's often hard to tell for which argument the error is coming. Since we have the named argument, we could use it in this situation.
34570b7
to
e447874
Compare
Alright, I think I have it now. |
Thank you! |
When a type is variadic, and multiple named arguments are used, it's often hard to tell for which argument the error is coming.
Since we have the named argument, we could use it in this situation.
Example:
Before the error would be:
And one had to inspect the different method calls to see where it might originate.
After:
It's immediately clear it's related to
foo
named argument.