From d924ee385e471e0de66ff8c34a1184527fa8fe6d Mon Sep 17 00:00:00 2001 From: Ivan Moroz Date: Fri, 29 May 2026 00:10:33 +0300 Subject: [PATCH] CONV-042: Implement options schema validator Co-Authored-By: Claude Opus 4.7 --- .../InvalidOptionsSchemaException.php | 43 ++++++++++ .../Converters/OptionsSchemaValidator.php | 79 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 app/Support/Converters/Exceptions/InvalidOptionsSchemaException.php create mode 100644 app/Support/Converters/OptionsSchemaValidator.php 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); + } + } + } +}