Skip to content

Commit

Permalink
fixes in export
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvsk committed Feb 24, 2023
1 parent ddae3c4 commit e5eb59f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Generator/Builder/Class/ExportMethodsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public function build(Dto $object, PhpNamespace $ns, ClassType $class): void
$class->addImplement('\\JsonSerializable');
$jsonSerializeMethod = $class->addMethod('jsonSerialize')
->setPublic()
->setReturnType('array')
->addBody('$array = [];')
->addBody('foreach (get_mangled_object_vars($this) as $var => $value) {')
->addBody(' $var = preg_replace("/.+\0/", "", $var);');
->addBody(' $var = substr($var, strrpos($var, "\\0") ?: 0);');

if ($this->dateFormat) {
$jsonSerializeMethod
Expand All @@ -65,8 +66,7 @@ public function build(Dto $object, PhpNamespace $ns, ClassType $class): void
->addBody(' }')
->addBody(' $array[$var] = $value;')
->addBody('}')
->addBody('return $array;')
->addAttribute('ReturnTypeWillChange');
->addBody('return $array;');
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Generator/Builder/EnumLegacyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ public function build(Enum $enum, PhpNamespace $ns): EnumType|ClassType

$class->addImplement('\\JsonSerializable');
$class->addMethod('jsonSerialize')
->addAttribute('ReturnTypeWillChange')
->setReturnType('array')
->addBody('return $this->value;');

$class->addMethod('__toString')
->setPublic()
->addBody('return $this->value;');

return $class;
Expand Down

0 comments on commit e5eb59f

Please sign in to comment.