From 89217e57dad334348210d55cc12664102e791a8d Mon Sep 17 00:00:00 2001 From: Martin Zurowietz Date: Thu, 28 Nov 2024 15:29:47 +0100 Subject: [PATCH] Improve validation null values could produce server errors. --- src/Annotation.php | 4 ++++ src/Category.php | 4 ++++ src/Coco.php | 4 ++++ src/Image.php | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/src/Annotation.php b/src/Annotation.php index 143f2d8..c994b53 100644 --- a/src/Annotation.php +++ b/src/Annotation.php @@ -40,6 +40,10 @@ public static function validate(array $data): void if (!array_key_exists($key, $data)) { throw new \Exception("Missing key '$key' in Annotation"); } + + if (is_null($data[$key])) { + throw new \Exception("Missing value for '$key' in Category"); + } } } diff --git a/src/Category.php b/src/Category.php index 013cc11..1ec07bf 100644 --- a/src/Category.php +++ b/src/Category.php @@ -26,6 +26,10 @@ public static function validate(array $data): void if (!array_key_exists($key, $data)) { throw new \Exception("Missing key '$key' in Category"); } + + if (is_null($data[$key])) { + throw new \Exception("Missing value for '$key' in Category"); + } } } } diff --git a/src/Coco.php b/src/Coco.php index 74179f3..11c6236 100644 --- a/src/Coco.php +++ b/src/Coco.php @@ -70,6 +70,10 @@ public static function validate(array $data): void if (!array_key_exists($key, $data)) { throw new \Exception("Missing key '$key' in Coco"); } + + if (is_null($data[$key])) { + throw new \Exception("Missing value for '$key' in Coco"); + } } } diff --git a/src/Image.php b/src/Image.php index 6bda21c..849fa47 100644 --- a/src/Image.php +++ b/src/Image.php @@ -39,6 +39,10 @@ public static function validate(array $data): void if (!array_key_exists($key, $data)) { throw new \Exception("Missing key '$key' in Image"); } + + if (is_null($data[$key])) { + throw new \Exception("Missing value for '$key' in Image"); + } } } }