From 3804fd35203b40c51cd212b403e200b918ef31cf Mon Sep 17 00:00:00 2001 From: Rick in t Veld Date: Thu, 16 May 2024 12:42:13 +0200 Subject: [PATCH] custom exceptions --- src/Builder/Uri/UriBuilder.php | 4 +++- src/Dto/Aggregator/AggregateRoot.php | 10 +++++++--- src/Exception/ClassNotFoundException.php | 13 +++++++++++++ src/Exception/NoDataFoundException.php | 13 +++++++++++++ src/Manager/ActionHandlerManager.php | 3 ++- 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/Exception/ClassNotFoundException.php create mode 100644 src/Exception/NoDataFoundException.php diff --git a/src/Builder/Uri/UriBuilder.php b/src/Builder/Uri/UriBuilder.php index a4317ca..fe17584 100644 --- a/src/Builder/Uri/UriBuilder.php +++ b/src/Builder/Uri/UriBuilder.php @@ -4,6 +4,8 @@ namespace App\Builder\Uri; +use App\Exception\ClassNotFoundException; + class UriBuilder { /** @@ -19,7 +21,7 @@ public function build(string $builder, array $parameters): string 'login' => (new LoginUriBuilder())($parameters), 'logout' => (new LogoutUriBuilder())($parameters), 'widget' => (new WidgetUriBuilder())($parameters), - default => throw new \Exception('Builder not found!'), + default => throw new ClassNotFoundException($builder), }; } } diff --git a/src/Dto/Aggregator/AggregateRoot.php b/src/Dto/Aggregator/AggregateRoot.php index f2d2b01..731646c 100644 --- a/src/Dto/Aggregator/AggregateRoot.php +++ b/src/Dto/Aggregator/AggregateRoot.php @@ -4,6 +4,10 @@ namespace App\Dto\Aggregator; +use App\Exception\AccountNotFoundException; +use App\Exception\NoDataFoundException; +use App\Exception\SessionNotFoundException; + class AggregateRoot implements AggregateInterface { /** @var array */ @@ -22,7 +26,7 @@ public function setAccounts(array $accounts): void public function getAccounts(): array { if (empty($this->accounts)) { - throw new \Exception('No accounts found!'); + throw new AccountNotFoundException(); } return $this->accounts; @@ -36,7 +40,7 @@ public function setData(mixed $data): void public function getData(): mixed { if ($this->data === null) { - throw new \Exception('No data found!'); + throw new NoDataFoundException(); } return $this->data; @@ -50,7 +54,7 @@ public function setSession(string $session): void public function getSession(): string { if (null === $this->session) { - throw new \Exception('The session is missing'); + throw new SessionNotFoundException(); } return $this->session; diff --git a/src/Exception/ClassNotFoundException.php b/src/Exception/ClassNotFoundException.php new file mode 100644 index 0000000..4c3285a --- /dev/null +++ b/src/Exception/ClassNotFoundException.php @@ -0,0 +1,13 @@ + $this->dailyDataActionHandler, 'daily_gain' => $this->dailyGainActionHandler, 'history' => $this->historyActionHandler, - default => throw new \Exception('Handler not found!'), + default => throw new ClassNotFoundException($handler), }; } }