From dd1e328520d55621f6c1c516c35731d8f208edf3 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Fri, 30 Oct 2020 15:52:23 +0100 Subject: [PATCH] Fix deprecated call to ReflectionType::__toString() --- src/UnresolvedValueException.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/UnresolvedValueException.php b/src/UnresolvedValueException.php index c4c992e..0e1d38b 100644 --- a/src/UnresolvedValueException.php +++ b/src/UnresolvedValueException.php @@ -29,7 +29,7 @@ public static function unresolvedParameter(\ReflectionParameter $parameter) : Un */ public static function unresolvedProperty(\ReflectionProperty $property) : UnresolvedValueException { - $message = 'The property %s::$%s could not be resolved'; + $message = 'The property %s::$%s could not be resolved.'; $message = sprintf($message, $property->getDeclaringClass()->getName(), $property->getName()); return new self($message); @@ -47,12 +47,27 @@ private static function getParameterName(\ReflectionParameter $parameter) : stri $parameterType = ''; if (null !== $type = $parameter->getType()) { - $parameterType = (string) $type . ' '; + $parameterType = self::getReflectionTypeName($type) . ' '; } return $parameterType . '$' . $parameter->getName(); } + private static function getReflectionTypeName(\ReflectionType $reflectionType) + { + if ($reflectionType instanceof \ReflectionNamedType) { + return $reflectionType->getName(); + } + + if ($reflectionType instanceof \ReflectionUnionType) { + return implode('|', array_map(function(\ReflectionNamedType $type) { + return $type->getName(); + }, $reflectionType->getTypes())); + } + + return ''; + } + /** * Returns the type (if any) + name of a function. *