-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
use proper return types in ErrorHandler and ArgumentResolver #32143
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -42,30 +42,24 @@ public function createArgumentMetadata($controller) | |||||
|
||||||
/** | ||||||
* Returns an associated type to the given parameter if available. | ||||||
* | ||||||
* @param \ReflectionParameter $parameter | ||||||
* | ||||||
* @return string|null | ||||||
*/ | ||||||
private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function) | ||||||
private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function): ?string | ||||||
{ | ||||||
if (!$type = $parameter->getType()) { | ||||||
return; | ||||||
return null; | ||||||
} | ||||||
$name = $type->getName(); | ||||||
$lcName = strtolower($name); | ||||||
|
||||||
if ('self' !== $lcName && 'parent' !== $lcName) { | ||||||
return $name; | ||||||
} | ||||||
if (!$function instanceof \ReflectionMethod) { | ||||||
return; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you cannot have a function using |
||||||
} | ||||||
if ('self' === $lcName) { | ||||||
return $function->getDeclaringClass()->name; | ||||||
} | ||||||
if ($parent = $function->getDeclaringClass()->getParentClass()) { | ||||||
return $parent->name; | ||||||
if ($function instanceof \ReflectionMethod) { | ||||||
$lcName = strtolower($name); | ||||||
switch ($lcName) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest to inline the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes seems fine, I just kept the variable because it was there before making merging easier. |
||||||
case 'self': | ||||||
return $function->getDeclaringClass()->name; | ||||||
case 'parent': | ||||||
return ($parent = $function->getDeclaringClass()->getParentClass()) ? $parent->name : null; | ||||||
} | ||||||
} | ||||||
|
||||||
return $name; | ||||||
} | ||||||
} |
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.
checking for Generator does not achieve the intended goal: having at least one yielded value.
I can do
return; yield $value;
which would return a generator but not yield anything.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 don't see a return type on the interface, so this would allow non-iterable return types as well. Perhaps the interface should receive a return type to enforce this (which is
\Generator
at the moment,iterable
after this PR) in 5.0? Could do with a typecheck on$resolved
Another solution would be to allow a
return $value
in the resolvers as generators are pretty much only required for an array structure being inserted as multiple arguments.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.
There are several different topics:
VariadicArgumentValue
class that you can return to resolve to several arguments. I think that's more clear and clean. Currently you can yield several values for non-variadic arguments which makes the ArgumentResolver behave very strange. But that's also a different topic. If you argree with something like this, feel free to create an issue/PR to keep track of that.