diff --git a/app/Support/Converters/Exceptions/InvalidOptionsSchemaException.php b/app/Support/Converters/Exceptions/InvalidOptionsSchemaException.php new file mode 100644 index 0000000..91e469f --- /dev/null +++ b/app/Support/Converters/Exceptions/InvalidOptionsSchemaException.php @@ -0,0 +1,43 @@ +validateChoiceOptions($key, $field['options'] ?? null); + } + } + } + + private function validateChoiceOptions(string $key, mixed $options): void + { + if (! is_array($options) || $options === []) { + throw InvalidOptionsSchemaException::becauseOptionsAreRequired($key); + } + + foreach ($options as $option) { + if (! is_array($option)) { + throw InvalidOptionsSchemaException::becauseOptionItemIsInvalid($key); + } + + $value = $option['value'] ?? null; + $label = $option['label'] ?? null; + + if ($value === null || ! is_string($label) || $label === '') { + throw InvalidOptionsSchemaException::becauseOptionItemIsInvalid($key); + } + } + } +}