Skip to content

Commit c307e5e

Browse files
committed
refactor: extract timeToString()
1 parent 903d6aa commit c307e5e

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

system/BaseModel.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,17 +1672,29 @@ protected function objectToArray($object, bool $onlyChanged = true, bool $recurs
16721672
$properties = $this->objectToRawArray($object, $onlyChanged, $recursive);
16731673

16741674
// Convert any Time instances to appropriate $dateFormat
1675-
if ($properties !== []) {
1676-
$properties = array_map(function ($value) {
1677-
if ($value instanceof Time) {
1678-
return $this->timeToDate($value);
1679-
}
1675+
return $this->timeToString($properties);
1676+
}
16801677

1681-
return $value;
1682-
}, $properties);
1678+
/**
1679+
* Convert any Time instances to appropriate $dateFormat.
1680+
*
1681+
* @param array<string, mixed> $properties
1682+
*
1683+
* @return array<string, mixed>
1684+
*/
1685+
protected function timeToString(array $properties): array
1686+
{
1687+
if ($properties === []) {
1688+
return [];
16831689
}
16841690

1685-
return $properties;
1691+
return array_map(function ($value) {
1692+
if ($value instanceof Time) {
1693+
return $this->timeToDate($value);
1694+
}
1695+
1696+
return $value;
1697+
}, $properties);
16861698
}
16871699

16881700
/**

0 commit comments

Comments
 (0)