diff --git a/src/Repository/DomainRepository.php b/src/Repository/DomainRepository.php index d4a5477..b86022a 100644 --- a/src/Repository/DomainRepository.php +++ b/src/Repository/DomainRepository.php @@ -47,9 +47,9 @@ class DomainRepository /** * @param int $id * - * @return \App\Entity\Domain + * @return false */ - public function findByID(int $id): Domain + public function findByID(int $id): bool|Domain { $sql = " SELECT id, name, panel_id, a, aaaa @@ -60,22 +60,23 @@ class DomainRepository $statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement->bindParam(param: ':id', var: $id); $statement->execute(); - $result = $statement->fetch(mode: PDO::FETCH_ASSOC); - - return new Domain(name: $result['name'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']); + if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) { + return new Domain(name: $result['name'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']); + } else { + return false; + } } catch (PDOException $e) { exit($e->getMessage()); } } - /** * @param String $name * - * @return \App\Entity\Domain + * @return \App\Entity\Domain|bool */ - public function findByName(string $name): Domain + public function findByName(string $name): Domain|bool { $sql = " SELECT id, name, panel_id, a, aaaa @@ -86,9 +87,13 @@ class DomainRepository $statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement->bindParam(param: ':name', var: $name); $statement->execute(); - $result = $statement->fetch(mode: PDO::FETCH_ASSOC); + if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) { + return new Domain(name: $result['name'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']); + + } else { + return false; + } - return new Domain(name: $result['name'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']); } catch (PDOException $e) { exit($e->getMessage()); }