From: Raphaƫl Gertz Date: Mon, 13 Oct 2025 11:47:29 +0000 (+0200) Subject: Function findByIdAsArray return null when user is not found X-Git-Tag: 0.0.1~46 X-Git-Url: https://git.rapsys.eu/blogbundle/commitdiff_plain/a52b673cf4c7e26bd65dff1c783c5087685d5d24 Function findByIdAsArray return null when user is not found --- diff --git a/Repository/UserRepository.php b/Repository/UserRepository.php index befe695..2aa8e3b 100644 --- a/Repository/UserRepository.php +++ b/Repository/UserRepository.php @@ -282,9 +282,9 @@ SQL; * Find user by id as array * * @param integer $id The user id - * @return array The article array + * @return ?array The article array */ - public function findByIdAsArray(int $id): array { + public function findByIdAsArray(int $id): ?array { //Set the request $req = <<addScalarResult('kt_titles', 'kt_titles', 'string'); //Get data - $data = $this->_em + if (($data = $this->_em ->createNativeQuery($req, $rsm) ->setParameter('id', $id) - ->getOneOrNullResult(); + ->getOneOrNullResult()) === null) { + //Return null + return $data; + } //Set return $return = [