Skip to content

Commit

Permalink
Fix deprecated call to ReflectionType::__toString()
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Oct 30, 2020
1 parent 9dc5b47 commit dd1e328
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/UnresolvedValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
*
Expand Down

0 comments on commit dd1e328

Please sign in to comment.