diff --git a/src/Hydrator.php b/src/Hydrator.php index 60fb29e..ae9a8a7 100644 --- a/src/Hydrator.php +++ b/src/Hydrator.php @@ -13,11 +13,18 @@ interface Hydrator * @return T * * @throws ClassNotSupported if the class is not supported or not found. + * @throws DenormalizationFailure if any normalizers throw an exception. + * @throws TypeMismatch if a TypeError occurs when setting a property value. + * @throws HydratorException Any other thrown exceptions should implement HydratorException. * * @template T of object */ public function hydrate(string $class, array $data): object; - /** @return array */ + /** + * @return array + * + * @throws HydratorException + */ public function extract(object $object): array; } diff --git a/src/HydratorException.php b/src/HydratorException.php index 5cc9811..7b080a8 100644 --- a/src/HydratorException.php +++ b/src/HydratorException.php @@ -4,6 +4,8 @@ namespace Patchlevel\Hydrator; -interface HydratorException +use Throwable; + +interface HydratorException extends Throwable { } diff --git a/src/HydratorWithContext.php b/src/HydratorWithContext.php index 6fea9dd..86d1877 100644 --- a/src/HydratorWithContext.php +++ b/src/HydratorWithContext.php @@ -16,6 +16,9 @@ interface HydratorWithContext extends Hydrator * @return T * * @throws ClassNotSupported if the class is not supported or not found. + * @throws DenormalizationFailure if any normalizers throw an exception. + * @throws TypeMismatch if a TypeError occurs when setting a property value. + * @throws HydratorException Any other thrown exceptions should implement HydratorException. * * @template T of object */ @@ -25,6 +28,8 @@ public function hydrate(string $class, array $data, array $context = []): object * @param array $context * * @return array + * + * @throws HydratorException */ public function extract(object $object, array $context = []): array; } diff --git a/src/MetadataHydrator.php b/src/MetadataHydrator.php index bab3ff4..2b91b21 100644 --- a/src/MetadataHydrator.php +++ b/src/MetadataHydrator.php @@ -62,6 +62,11 @@ public function __construct( * * @return T * + * @throws ClassNotSupported if the target class does not exist. + * @throws DenormalizationFailure if any normalizers throw an exception. + * @throws TypeMismatch if a TypeError occurs when setting a property value. + * @throws HydratorException Any other thrown exceptions should implement HydratorException. + * * @template T of object */ public function hydrate(string $class, array $data, array $context = []): object @@ -96,6 +101,9 @@ function () use ($metadata, $data, $context): object { * * @return T * + * @throws DenormalizationFailure if any normalizers throw an exception. + * @throws TypeMismatch if a TypeError occurs when setting a property value. + * * @template T of object */ private function doHydrate(ClassMetadata $metadata, array $data, array $context = []): object @@ -179,6 +187,11 @@ private function doHydrate(ClassMetadata $metadata, array $data, array $context * @param array $context * * @return array + * + * @throws CircularReference + * @throws NormalizationFailure + * @throws NormalizationMissing + * @throws ClassNotFound */ public function extract(object $object, array $context = []): array {