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. *