Skip to content

Commit c058b98

Browse files
committed
stan
1 parent 88cd2bb commit c058b98

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Generator/EnumGenerator.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function getCaseName(string $value): string
2222
return 'V_' . $sanitized;
2323
}
2424

25-
return $sanitized;
25+
return (string)$sanitized;
2626
}
2727

2828
public function generate(Specification $specification, PhpFileCollection $fileRegistry): void
@@ -66,6 +66,10 @@ private function generateEnum(Field $root, PhpFileCollection $fileRegistry): voi
6666

6767
private function generateEnumConsts(Field $root): array
6868
{
69+
if ($root->getEnumValues() === null) {
70+
return [];
71+
}
72+
6973
$statements = [];
7074
foreach ($root->getEnumValues() as $value) {
7175
$statements[] = $this

src/Generator/RequestGenerator.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,15 @@ protected function generateConstructor(
149149
->param($field->getPhpVariableName())
150150
->setType($field->getPhpTypeHint(), $field->isNullable());
151151

152-
if ($field->getDefault() !== null) {
153-
if ($field->isEnum() && $this->phpVersion->isEnumSupported()) {
154-
$param->setDefault($this->builder->classConstFetch($field->getPhpClassName(), EnumGenerator::getCaseName($field->getDefault())));
152+
if (($default = $field->getDefault()) !== null) {
153+
if ($field->isEnum() && $this->phpVersion->isEnumSupported() && (
154+
is_string($default)
155+
|| is_integer($default)
156+
)) {
157+
$param->setDefault($this->builder->classConstFetch(
158+
$field->getPhpClassName(),
159+
EnumGenerator::getCaseName((string)$default)
160+
));
155161
} else {
156162
$param->setDefault($field->getDefault());
157163
}

0 commit comments

Comments
 (0)