Skip to content

Commit a5aa529

Browse files
authored
fix: avoid ReflectionEnum usage (#5453)
1 parent 9421ba5 commit a5aa529

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/JsonSchema/TypeFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,16 @@ private function getClassType(?string $className, bool $nullable, string $format
117117
];
118118
}
119119
if (!$this->isResourceClass($className) && is_a($className, \BackedEnum::class, true)) {
120-
$rEnum = new \ReflectionEnum($className);
121-
$enumCases = array_map(static fn (\ReflectionEnumBackedCase $rCase) => $rCase->getBackingValue(), $rEnum->getCases());
120+
$enumCases = array_map(static fn (\BackedEnum $enum): string|int => $enum->value, $className::cases());
121+
122+
$type = \is_string($enumCases[0] ?? '') ? 'string' : 'int';
123+
122124
if ($nullable) {
123125
$enumCases[] = null;
124126
}
125127

126128
return [
127-
'type' => (string) $rEnum->getBackingType(),
129+
'type' => $type,
128130
'enum' => $enumCases,
129131
];
130132
}

0 commit comments

Comments
 (0)