Skip to content

Commit

Permalink
added tags
Browse files Browse the repository at this point in the history
  • Loading branch information
KoNekoD committed Apr 21, 2024
1 parent 06daaa8 commit 693edc8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/OutputGenerator/Go/GoOutputGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ private function convert(DtoType $dto, DtoList $dtoList): string
if ($dto->getExpressionType()->equals(ExpressionType::class())) {
$structProps = '';

$maxPropLen = 0;
$maxPropRowLen = 0;
$maxStructPropNameLength = 0;
$maxStructPropNameAndTypeLength = 0;
foreach ($dto->getProperties() as $prop) {
$maxPropLen = max($maxPropLen, strlen($prop->getName()));
$maxStructPropNameLength = max($maxStructPropNameLength, strlen($prop->getName()));
}

$normProps = [];
foreach ($dto->getProperties() as $prop) {
$spaces = str_repeat(' ', $maxPropLen - strlen($prop->getName()) + 1);
$spaces = str_repeat(' ', $maxStructPropNameLength - strlen($prop->getName()) + 1);

$tagsTemplate = '`json:"%s"`';
if ($prop->getType() instanceof PhpOptionalType) {
Expand All @@ -70,15 +70,15 @@ private function convert(DtoType $dto, DtoList $dtoList): string
ucfirst($prop->getName()),
$this->resolver->resolve($prop->getType(), $dto, $dtoList)
);
$maxPropRowLen = max($maxPropRowLen, strlen($structPropsRow));
$maxStructPropNameAndTypeLength = max($maxStructPropNameAndTypeLength, strlen($structPropsRow));
$normProps[] = [
'structPropsRow' => $structPropsRow,
'tagsRow' => sprintf($tagsTemplate, $prop->getName()),
];
}

foreach ($normProps as $prop) {
$tagsSpaces = str_repeat(' ', $maxPropRowLen - strlen($prop['structPropsRow']) + 1);
$tagsSpaces = str_repeat(' ', $maxStructPropNameAndTypeLength - strlen($prop['structPropsRow']) + 1);
$structProps .= sprintf("\n\t%s$tagsSpaces%s", $prop['structPropsRow'], $prop['tagsRow']);
}

Expand Down

0 comments on commit 693edc8

Please sign in to comment.