handled case domain not found

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-31 19:10:51 +01:00
parent 574b960ed1
commit d1e67fce03
1 changed files with 7 additions and 5 deletions

View File

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