mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Sort type for model update visitor. (#6437)
This commit is contained in:
parent
0bb4cca221
commit
d6b4c299d2
@ -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
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user