From 6446309af3094ad7e422bb77f6035c84335044e0 Mon Sep 17 00:00:00 2001 From: Yura Rodchyn <80677954+yrodchyn@users.noreply.github.com> Date: Tue, 26 May 2026 14:23:52 +0300 Subject: [PATCH 1/2] Allow findOne method to accept null ID --- src/Repository.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Repository.php b/src/Repository.php index 603d7c2..8dd5b23 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -79,11 +79,15 @@ public function __construct(Database $db, string $klass) /** * Find a single entity by its ID * - * @param int $id ID of the entity + * @param ?int $id ID of the entity * @psalm-return ?TEntity */ - public function findOne(int $id): ?Entity + public function findOne(?int $id): ?Entity { + if ($id === null) { + return null; + } + return $this->findOneBy([ 'id' => $id, ]); From 63085dc8be7e949a289c8886fb4bc3666fd09b94 Mon Sep 17 00:00:00 2001 From: Yura Rodchyn <80677954+yrodchyn@users.noreply.github.com> Date: Tue, 26 May 2026 14:24:27 +0300 Subject: [PATCH 2/2] Allow nullable ID parameter in findOne method --- src/Database.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Database.php b/src/Database.php index 868945a..c76e550 100644 --- a/src/Database.php +++ b/src/Database.php @@ -268,10 +268,10 @@ public function getRepository(string $klass): Repository * @psalm-return ?TEntity * * @param string $klass Entity class name - * @param int $id ID of the entity + * @param ?int $id ID of the entity * @return ?Entity */ - public function findOne(string $klass, int $id): ?Entity + public function findOne(string $klass, ?int $id): ?Entity { return $this->getRepository($klass)->findOne($id); }