From 1052e00cf59123b0bdd215834081585856523725 Mon Sep 17 00:00:00 2001 From: tracer Date: Mon, 31 Jan 2022 19:12:17 +0100 Subject: [PATCH] handled case domain not found, also in findbyid Signed-off-by: tracer --- src/Repository/ApikeyRepository.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Repository/ApikeyRepository.php b/src/Repository/ApikeyRepository.php index a68b06e..216d871 100644 --- a/src/Repository/ApikeyRepository.php +++ b/src/Repository/ApikeyRepository.php @@ -76,9 +76,9 @@ class ApikeyRepository /** * @param String $prefix * - * @return \App\Entity\Apikey + * @return \App\Entity\Apikey|bool */ - public function findByPrefix(String $prefix): Apikey + public function findByPrefix(String $prefix): Apikey|bool { $sql = " SELECT name, api_token @@ -89,8 +89,11 @@ class ApikeyRepository $statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement->bindParam(param: ':prefix', var: $prefix); $statement->execute(); - $result = $statement->fetch(mode: PDO::FETCH_ASSOC); - return new Apikey(name: $result['name'], apiTokenPrefix: $result['api_token_prefix'], apiToken: $result['api_token_result'], id: $result['id']); + if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) { + return new Apikey(name: $result['name'], apiTokenPrefix: $result['api_token_prefix'], apiToken: $result['api_token_result'], id: $result['id']); + } else { + return false; + } } catch (PDOException $e) { exit($e->getMessage()); }