From 6e5119348e28b1bca5fc38e0d567c74cf687daee Mon Sep 17 00:00:00 2001 From: julien Date: Mon, 9 Mar 2026 02:11:53 +0100 Subject: [PATCH] Works --- public/index.php | 5 +++-- src/Repositories/PostRepositoryMedoo.php | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/public/index.php b/public/index.php index 5322b81..8e5c882 100644 --- a/public/index.php +++ b/public/index.php @@ -36,8 +36,9 @@ $medooOptions = [ 'charset' => 'utf8', ]; -// Certaines variantes/versions de Medoo s'attendent à 'database_name'. -// Dupliquer la valeur pour éviter le warning. +// Certaines variantes/versions de Medoo (selon l'installation/composer.lock) +// peuvent émettre un warning en cherchant 'database_name'. +// Dupliquer la valeur pour éviter le warning sans changer le comportement. if (!isset($medooOptions['database_name'])) { $medooOptions['database_name'] = $medooOptions['database_file']; } diff --git a/src/Repositories/PostRepositoryMedoo.php b/src/Repositories/PostRepositoryMedoo.php index 4940e9d..7055e6e 100644 --- a/src/Repositories/PostRepositoryMedoo.php +++ b/src/Repositories/PostRepositoryMedoo.php @@ -19,15 +19,33 @@ class PostRepositoryMedoo $this->db = $db; } + /** + * @return array + */ 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