Skip to content

Commit

Permalink
Use getName() if available
Browse files Browse the repository at this point in the history
ReflectionType::__toString() has been deprecated in favor of
ReflectionNamedType::getName(). The documentation states that this:
> As of PHP 7.1.0, ReflectionType::__toString() is deprecated, and
> ReflectionParamater::getType() *may* return an instance of
> ReflectionNamedType. To get the name of the parameter type,
> ReflectionNamedType() is available in this case.

Since this implies there is no guarantee to have a ReflectionNamedType,
I added a type check, falling back to the use of the deprecated API.
  • Loading branch information
greg0ire committed Jul 17, 2019
1 parent 0568680 commit 54df46c
Showing 1 changed file with 1 addition and 1 deletion.
Expand Up @@ -218,7 +218,7 @@ private function guessHandledClasses(\ReflectionClass $handlerClass, string $ser
}

if ($type->isBuiltin()) {
throw new RuntimeException(sprintf('Invalid handler service "%s": type-hint of argument "$%s" in method "%s::__invoke()" must be a class , "%s" given.', $serviceId, $parameters[0]->getName(), $handlerClass->getName(), $type));
throw new RuntimeException(sprintf('Invalid handler service "%s": type-hint of argument "$%s" in method "%s::__invoke()" must be a class , "%s" given.', $serviceId, $parameters[0]->getName(), $handlerClass->getName(), $type instanceof \ReflectionNamedType ? $type->getName() : (string) $type));
}

return [$parameters[0]->getType()->getName()];
Expand Down

0 comments on commit 54df46c

Please sign in to comment.