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); } 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, ]);