From 2609f41a7c021004bdc2a0069fc149fb69325dfc Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 25 Feb 2026 16:28:31 +0100 Subject: [PATCH] solve empty array error --- src/Controller/OAuth2Controller.php | 31 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Controller/OAuth2Controller.php b/src/Controller/OAuth2Controller.php index 1f2c008..648111e 100644 --- a/src/Controller/OAuth2Controller.php +++ b/src/Controller/OAuth2Controller.php @@ -37,24 +37,27 @@ class OAuth2Controller extends AbstractController $uos = $uoRepository->findBy(['users' => $user]); $result = []; - foreach ($uos as $uo) { - $result[] = ['organization' => [ - 'id' => $uo->getOrganization()->getId(), - 'name' => $uo->getOrganization()->getName(), - 'role' => $uo->getRole()->getName() - ] - ]; - if ($uo->getRole()->getName() === "ADMIN") { - $projets = $uo->getOrganization()->getProjects()->toArray(); - $result[count($result) - 1]['organization']['projects'] = array_map(function ($projet) { - return [ - 'id' => $projet->getId(), + if (!empty($uos)) { + foreach ($uos as $uo) { + $result[] = ['organization' => [ + 'id' => $uo->getOrganization()->getId(), + 'name' => $uo->getOrganization()->getName(), + 'role' => $uo->getRole()->getName() + ] + ]; + if ($uo->getRole()->getName() === "ADMIN") { + $projets = $uo->getOrganization()->getProjects()->toArray(); + $result[count($result) - 1]['organization']['projects'] = array_map(function ($projet) { + return [ + 'id' => $projet->getId(), // 'name' => $projet->getName() - ]; - }, $projets); + ]; + }, $projets); + } } } + $this->loggerService->logUserAction($user->getId(), $user->getId(), 'Accessed userinfo endpoint'); return new JsonResponse([ 'id' => $user->getId(),