diff --git a/src/Repository/ApikeyRepository.php b/src/Repository/ApikeyRepository.php index 2d0c91f..a68b06e 100644 --- a/src/Repository/ApikeyRepository.php +++ b/src/Repository/ApikeyRepository.php @@ -48,9 +48,9 @@ class ApikeyRepository /** * @param Int $id * - * @return \App\Entity\Apikey + * @return \App\Entity\Apikey|bool */ - public function findByID(Int $id): Apikey + public function findByID(Int $id): Apikey|bool { $sql = " SELECT id, name, api_token_prefix, api_token @@ -62,9 +62,11 @@ class ApikeyRepository $statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement->bindParam(param: ':id', var: $id); $statement->execute(); - $result = $statement->fetch(mode: PDO::FETCH_ASSOC); - print_r($result); - return new Apikey(name: $result['name'], apiTokenPrefix: $result['api_token_prefix'], apiToken: $result['api_token'], 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'], id: $result['id']); + } else { + return false; + } } catch (PDOException $e) { exit($e->getMessage()); }