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()); }