Skip to content

Commit

Permalink
Sort type for model update visitor. (#6437)
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Jan 4, 2024
1 parent 1dd1014 commit a3ff1e7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Commands/Ast/ModelUpdateVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,17 @@ protected function parseProperty(string $doc): string
}
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;
Expand All @@ -221,6 +226,7 @@ protected function parseProperty(string $doc): string

protected function parsePropertyType(string $type): string
{
$origin = $type;
$isArray = false;
if (str_ends_with($type, '[]')) {
$isArray = true;
Expand All @@ -233,9 +239,11 @@ protected function parsePropertyType(string $type): string
if ($isArray) {
$type .= '[]';
}

return $type;
}

return $type;
return $origin;
}

protected function initPropertiesFromMethods()
Expand Down

0 comments on commit a3ff1e7

Please sign in to comment.