door: don't require default row in database

This commit is contained in:
2026-01-13 11:35:34 +09:00
parent b9992c7c57
commit 32ba9c11f7
6 changed files with 36 additions and 17 deletions

View File

@@ -70,9 +70,9 @@ class Door {
}
/**
* @return array{time: DateTimeImmutable, open: bool}
* @return ?array{time: DateTimeImmutable, open: bool}
*/
public function getCurrent(): array {
public function getCurrent(): ?array {
$query = '
SELECT
time,
@@ -85,6 +85,10 @@ class Door {
$statement->execute();
$row = $statement->fetch();
if (!$row) {
return null;
}
return [
'time' => (new DateTimeImmutable)->setTimestamp((int) $row['time']),
'open' => (bool) $row['open'],