]> Raphaël G. Git Repositories - blogbundle/commitdiff
Function findByIdAsArray return null when user is not found
authorRaphaël Gertz <git@rapsys.eu>
Mon, 13 Oct 2025 11:47:29 +0000 (13:47 +0200)
committerRaphaël Gertz <git@rapsys.eu>
Mon, 13 Oct 2025 11:47:29 +0000 (13:47 +0200)
Repository/UserRepository.php

index befe69528cd941e3e2cd0bf2909d2c0271893ceb..2aa8e3bffe20d60490a0d2b42d0d1628749cf54a 100644 (file)
@@ -282,9 +282,9 @@ SQL;
         * Find user by id as array
         *
         * @param integer $id The user id
         * 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 = <<<SQL
 SELECT
                //Set the request
                $req = <<<SQL
 SELECT
@@ -401,10 +401,13 @@ SQL;
                        ->addScalarResult('kt_titles', 'kt_titles', 'string');
 
                //Get data
                        ->addScalarResult('kt_titles', 'kt_titles', 'string');
 
                //Get data
-               $data = $this->_em
+               if (($data = $this->_em
                        ->createNativeQuery($req, $rsm)
                        ->setParameter('id', $id)
                        ->createNativeQuery($req, $rsm)
                        ->setParameter('id', $id)
-                       ->getOneOrNullResult();
+                       ->getOneOrNullResult()) === null) {
+                       //Return null
+                       return $data;
+               }
 
                //Set return
                $return = [
 
                //Set return
                $return = [