Works
This commit is contained in:
@@ -19,15 +19,33 @@ class PostRepositoryMedoo
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{id:int, title:string, content:string}>
|
||||
*/
|
||||
public function allDesc(): array
|
||||
{
|
||||
return $this->db->select('post', ['id', 'title', 'content'], ['ORDER' => ['id' => 'DESC']]);
|
||||
$rows = $this->db->select('post', ['id', 'title', 'content'], ['ORDER' => ['id' => 'DESC']]);
|
||||
return is_array($rows) ? $rows : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{id:int, title:string, content:string}|null
|
||||
*/
|
||||
public function find(int $id): ?array
|
||||
{
|
||||
$row = $this->db->get('post', ['id', 'title', 'content'], ['id' => $id]);
|
||||
return $row === null ? null : $row;
|
||||
|
||||
// Medoo peut retourner false ou empty si rien trouvé — normaliser en null.
|
||||
if (empty($row) || $row === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Forcer types et clés attendues
|
||||
return [
|
||||
'id' => (int)($row['id'] ?? 0),
|
||||
'title' => (string)($row['title'] ?? ''),
|
||||
'content' => (string)($row['content'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
public function create(array $data): int
|
||||
|
||||
Reference in New Issue
Block a user