Skip to content

Commit

Permalink
stan
Browse files Browse the repository at this point in the history
  • Loading branch information
vsouz4 committed May 17, 2024
1 parent 88cd2bb commit c058b98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Generator/EnumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function getCaseName(string $value): string
return 'V_' . $sanitized;
}

return $sanitized;
return (string)$sanitized;
}

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

private function generateEnumConsts(Field $root): array
{
if ($root->getEnumValues() === null) {
return [];
}

$statements = [];
foreach ($root->getEnumValues() as $value) {
$statements[] = $this
Expand Down
12 changes: 9 additions & 3 deletions src/Generator/RequestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,15 @@ protected function generateConstructor(
->param($field->getPhpVariableName())
->setType($field->getPhpTypeHint(), $field->isNullable());

if ($field->getDefault() !== null) {
if ($field->isEnum() && $this->phpVersion->isEnumSupported()) {
$param->setDefault($this->builder->classConstFetch($field->getPhpClassName(), EnumGenerator::getCaseName($field->getDefault())));
if (($default = $field->getDefault()) !== null) {
if ($field->isEnum() && $this->phpVersion->isEnumSupported() && (
is_string($default)
|| is_integer($default)
)) {
$param->setDefault($this->builder->classConstFetch(
$field->getPhpClassName(),
EnumGenerator::getCaseName((string)$default)
));
} else {
$param->setDefault($field->getDefault());
}
Expand Down

0 comments on commit c058b98

Please sign in to comment.