diff --git a/src/TypeCaster/HydratorTypeCaster.php b/src/TypeCaster/HydratorTypeCaster.php index 5dea7a9..a0c0e24 100644 --- a/src/TypeCaster/HydratorTypeCaster.php +++ b/src/TypeCaster/HydratorTypeCaster.php @@ -4,7 +4,6 @@ namespace Yiisoft\Hydrator\TypeCaster; -use ReflectionClass; use ReflectionNamedType; use ReflectionUnionType; use Yiisoft\Hydrator\Exception\NonInstantiableException; @@ -57,16 +56,12 @@ private function castInternal(array $value, ReflectionNamedType $type, HydratorI $class = $type->getName(); - $reflection = new ReflectionClass($class); - if ($reflection->isInstantiable()) { - try { - $object = $hydrator->create($class, $value); - } catch (NonInstantiableException) { - return Result::fail(); - } - return Result::success($object); + try { + $object = $hydrator->create($class, $value); + } catch (NonInstantiableException) { + return Result::fail(); } - return Result::fail(); + return Result::success($object); } }