Skip to content

Commit

Permalink
Fix invalid go generation (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
KoNekoD authored Apr 22, 2024
1 parent 19d982f commit b642a4b
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/OutputGenerator/Go/GoEnumResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private function convertEnumToGoEnumProperties(array $properties, string $enum):
}
$this->usedConstantsStore[] = $const;

$spaces = str_repeat(' ', $maxEnumPropNameLength - strlen($prop->getName()) + 1);
$spaces = str_repeat(' ', $maxEnumPropNameLength - strlen($const) + 1);

$value = $prop->isNumeric() ? $prop->getValue() : sprintf('"%s"', $prop->getValue());
$string .= sprintf("\n\t%s$spaces%s = %s", $const, $enum, $value);
Expand Down
4 changes: 2 additions & 2 deletions src/OutputGenerator/Go/GoTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ private function resolveBase(PhpBaseType $type, ?DtoType $dto): string
$type->equalsTo(PhpBaseType::string()) => 'string',
$type->equalsTo(PhpBaseType::bool()) => 'bool',
$type->equalsTo(PhpBaseType::mixed()),
$type->equalsTo(PhpBaseType::object()) => 'interface{}',
$type->equalsTo(PhpBaseType::object()),
$type->equalsTo(PhpBaseType::array()),
$type->equalsTo(PhpBaseType::iterable()) => '[]interface{}',
$type->equalsTo(PhpBaseType::iterable()) => 'interface{}',
$type->equalsTo(PhpBaseType::null()) => 'null',
$type->equalsTo(PhpBaseType::self()) => "*{$dto->getName()}", // * for prevent recursive definition
default => throw new Exception('Unknown base PHP type: %s' . json_encode($type))
Expand Down
6 changes: 3 additions & 3 deletions src/OutputGenerator/Go/OutputFilesProcessorProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static function provide(?OutputFilesProcessor $outputFilesProcessor = nul
[
new PrependAutogeneratedNoticeFileProcessor(
text: <<<TEXT
// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT!
// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT!
// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT!
// Code generated by php-converter. DO NOT EDIT.
// Code generated by php-converter. DO NOT EDIT.
// Code generated by php-converter. DO NOT EDIT.
package gen
Expand Down
2 changes: 2 additions & 0 deletions tests/OutputGenerator/Fixtures/NestedDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ final class PermissionsEnum extends Enum
private const VIEW = 'view';

private const EDIT = 'edit';

private const CREATE_EXTRA_SUPER_FILE = 'create-extra-super-file';
}

class FullName
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
{
"name": "EDIT",
"value": "edit"
},
{
"name": "CREATE_EXTRA_SUPER_FILE",
"value": "create-extra-super-file"
}
],
"generics": []
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
{
"name": "EDIT",
"value": "edit"
},
{
"name": "CREATE_EXTRA_SUPER_FILE",
"value": "create-extra-super-file"
}
],
"generics": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export enum NumberEnum {
export enum PermissionsEnum {
VIEW = 'view',
EDIT = 'edit',
CREATE_EXTRA_SUPER_FILE = 'create-extra-super-file',
}

export type Profile = {
Expand Down

0 comments on commit b642a4b

Please sign in to comment.