handled case domain not found, also in findbyid

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-31 19:12:17 +01:00
parent d1e67fce03
commit 1052e00cf5
1 changed files with 7 additions and 4 deletions

View File

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