Sort type for model update visitor. (#6437)

This commit is contained in:
李铭昕 2024-01-04 21:47:09 +08:00 committed by GitHub
parent 0bb4cca221
commit d6b4c299d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -11,7 +11,7 @@
## Optimized
- [#6435](https://github.com/hyperf/hyperf/pull/6435) Optimized model generator which can generate property comments with `use`.
- [#6435](https://github.com/hyperf/hyperf/pull/6435) [#6437](https://github.com/hyperf/hyperf/pull/6437) Optimized model generator which can generate property comments with `use`.
# v3.1.4 - 2023-12-29

View File

@ -197,12 +197,17 @@ class ModelUpdateVisitor extends NodeVisitorAbstract
}
foreach ($this->properties as $name => $property) {
$type = $property['type'];
foreach ($type as $i => $item) {
$type[$i] = $this->parsePropertyType($item);
$sorted = [];
foreach ($type as $item) {
if ($item === 'null') {
array_unshift($sorted, $item);
continue;
}
$sorted[] = $this->parsePropertyType($item);
}
$comment = $property['comment'] ?? '';
$type = implode('|', $type);
$type = implode('|', $sorted);
if ($property['read'] && $property['write']) {
$doc .= sprintf(' * @property %s $%s %s', $type, $name, $comment) . PHP_EOL;
continue;
@ -221,6 +226,7 @@ class ModelUpdateVisitor extends NodeVisitorAbstract
protected function parsePropertyType(string $type): string
{
$origin = $type;
$isArray = false;
if (str_ends_with($type, '[]')) {
$isArray = true;
@ -233,9 +239,11 @@ class ModelUpdateVisitor extends NodeVisitorAbstract
if ($isArray) {
$type .= '[]';
}
return $type;
}
return $type;
return $origin;
}
protected function initPropertiesFromMethods()