Skip to content

Commit 6fa0dd1

Browse files
authored
Merge pull request #48 from collecthor/fix-singlechoice-int-value
fix: integer option could lead to bad display value
2 parents e8a640f + 564722f commit 6fa0dd1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/ParserHelpers.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ private function extractChoices(mixed $choices): array
213213
foreach ($choices as $choice) {
214214
if (is_array($choice) && isset($choice['value'])) {
215215
$value = $choice['value'];
216-
$displayValues = $this->extractLocalizedTexts($choice, 'text', ['default' => $choice['value']]);
216+
if (!is_scalar($value)) {
217+
throw new \InvalidArgumentException('Values must be scalar, got: ' . print_r($choice, true));
218+
}
219+
$displayValues = $this->extractLocalizedTexts($choice, 'text', ['default' => (string) $value]);
217220
} elseif (is_string($choice) || is_int($choice)) {
218221
$value = $choice;
219222
$displayValues = [];
@@ -225,10 +228,8 @@ private function extractChoices(mixed $choices): array
225228

226229
if (is_int($value)) {
227230
$result[] = new IntegerValueOption($value, $displayValues);
228-
} elseif (is_scalar($value)) {
229-
$result[] = new StringValueOption((string) $value, $displayValues);
230231
} else {
231-
throw new \InvalidArgumentException('Values must be scalar, got: ' . print_r($choice, true));
232+
$result[] = new StringValueOption((string) $value, $displayValues);
232233
}
233234
}
234235

0 commit comments

Comments
 (0)