From 207edd9cc873fb71ad7f00a79ee14f38df835494 Mon Sep 17 00:00:00 2001
From: kenjis <kenji.uui@gmail.com>
Date: Wed, 6 Jul 2022 11:36:38 +0900
Subject: [PATCH 1/8] feat: add BaseException interface

---
 src/Exceptions/BaseException.php | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 src/Exceptions/BaseException.php

diff --git a/src/Exceptions/BaseException.php b/src/Exceptions/BaseException.php
new file mode 100644
index 000000000..ddaa8c1a7
--- /dev/null
+++ b/src/Exceptions/BaseException.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace CodeIgniter\Shield\Exceptions;
+
+use Throwable;
+
+/**
+ * Base Exception Interface for Shield
+ */
+interface BaseException extends Throwable
+{
+}

From 756f8dc23cc6b4f9507d0d136d2c6d3285006531 Mon Sep 17 00:00:00 2001
From: kenjis <kenji.uui@gmail.com>
Date: Wed, 6 Jul 2022 11:36:57 +0900
Subject: [PATCH 2/8] feat: add HTTPException for Shield

---
 src/Exceptions/HTTPException.php | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 src/Exceptions/HTTPException.php

diff --git a/src/Exceptions/HTTPException.php b/src/Exceptions/HTTPException.php
new file mode 100644
index 000000000..157673bc1
--- /dev/null
+++ b/src/Exceptions/HTTPException.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace CodeIgniter\Shield\Exceptions;
+
+use CodeIgniter\HTTP\Exceptions\HTTPException as FrameworkHTTPException;
+
+class HTTPException extends FrameworkHTTPException implements BaseException
+{
+}

From 2f58a5d951e25a4be86f5a33312308c2dedb3759 Mon Sep 17 00:00:00 2001
From: kenjis <kenji.uui@gmail.com>
Date: Wed, 6 Jul 2022 11:40:36 +0900
Subject: [PATCH 3/8] refactor: use BaseException and HTTPException

---
 src/Authentication/AuthenticationException.php  | 5 ++---
 src/Authentication/Passwords/PwnedValidator.php | 2 +-
 src/Authorization/AuthorizationException.php    | 4 ++--
 src/Exceptions/LogicException.php               | 2 +-
 src/Exceptions/RuntimeException.php             | 2 +-
 tests/Unit/PwnedValidatorTest.php               | 2 +-
 6 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/Authentication/AuthenticationException.php b/src/Authentication/AuthenticationException.php
index d1311a039..219e05d3a 100644
--- a/src/Authentication/AuthenticationException.php
+++ b/src/Authentication/AuthenticationException.php
@@ -2,10 +2,9 @@
 
 namespace CodeIgniter\Shield\Authentication;
 
-use CodeIgniter\HTTP\Exceptions\HTTPException;
-use Exception;
+use CodeIgniter\Shield\Exceptions\HTTPException;
 
-class AuthenticationException extends Exception
+class AuthenticationException extends HTTPException
 {
     protected $code = 403;
 
diff --git a/src/Authentication/Passwords/PwnedValidator.php b/src/Authentication/Passwords/PwnedValidator.php
index d643b4b20..8e0587f7e 100644
--- a/src/Authentication/Passwords/PwnedValidator.php
+++ b/src/Authentication/Passwords/PwnedValidator.php
@@ -3,9 +3,9 @@
 namespace CodeIgniter\Shield\Authentication\Passwords;
 
 use CodeIgniter\Config\Services;
-use CodeIgniter\HTTP\Exceptions\HTTPException;
 use CodeIgniter\Shield\Authentication\AuthenticationException;
 use CodeIgniter\Shield\Entities\User;
+use CodeIgniter\Shield\Exceptions\HTTPException;
 use CodeIgniter\Shield\Result;
 
 /**
diff --git a/src/Authorization/AuthorizationException.php b/src/Authorization/AuthorizationException.php
index b025d10c5..62c4d98e3 100644
--- a/src/Authorization/AuthorizationException.php
+++ b/src/Authorization/AuthorizationException.php
@@ -2,9 +2,9 @@
 
 namespace CodeIgniter\Shield\Authorization;
 
-use Exception;
+use CodeIgniter\Shield\Exceptions\HTTPException;
 
-class AuthorizationException extends Exception
+class AuthorizationException extends HTTPException
 {
     protected $code = 401;
 
diff --git a/src/Exceptions/LogicException.php b/src/Exceptions/LogicException.php
index c59b59096..208c9fd26 100644
--- a/src/Exceptions/LogicException.php
+++ b/src/Exceptions/LogicException.php
@@ -2,6 +2,6 @@
 
 namespace CodeIgniter\Shield\Exceptions;
 
-class LogicException extends \LogicException
+class LogicException extends \LogicException implements BaseException
 {
 }
diff --git a/src/Exceptions/RuntimeException.php b/src/Exceptions/RuntimeException.php
index 588ac2c0c..b60ecbfe5 100644
--- a/src/Exceptions/RuntimeException.php
+++ b/src/Exceptions/RuntimeException.php
@@ -2,6 +2,6 @@
 
 namespace CodeIgniter\Shield\Exceptions;
 
-class RuntimeException extends \RuntimeException
+class RuntimeException extends \RuntimeException implements BaseException
 {
 }
diff --git a/tests/Unit/PwnedValidatorTest.php b/tests/Unit/PwnedValidatorTest.php
index b303b3389..77038ff93 100644
--- a/tests/Unit/PwnedValidatorTest.php
+++ b/tests/Unit/PwnedValidatorTest.php
@@ -2,12 +2,12 @@
 
 namespace Tests\Unit;
 
-use CodeIgniter\HTTP\Exceptions\HTTPException;
 use CodeIgniter\HTTP\Response;
 use CodeIgniter\Shield\Authentication\AuthenticationException;
 use CodeIgniter\Shield\Authentication\Passwords\PwnedValidator;
 use CodeIgniter\Shield\Config\Auth as AuthConfig;
 use CodeIgniter\Shield\Config\Services;
+use CodeIgniter\Shield\Exceptions\HTTPException;
 use CodeIgniter\Test\CIUnitTestCase;
 use Config\App;
 

From 615a44351ba5aba2e4539f2ed7261c2faf7435c1 Mon Sep 17 00:00:00 2001
From: kenjis <kenji.uui@gmail.com>
Date: Wed, 6 Jul 2022 11:51:19 +0900
Subject: [PATCH 4/8] feat: add InvalidArgumentException for Shield

---
 src/Exceptions/InvalidArgumentException.php | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 src/Exceptions/InvalidArgumentException.php

diff --git a/src/Exceptions/InvalidArgumentException.php b/src/Exceptions/InvalidArgumentException.php
new file mode 100644
index 000000000..7f7e22cc6
--- /dev/null
+++ b/src/Exceptions/InvalidArgumentException.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace CodeIgniter\Shield\Exceptions;
+
+class InvalidArgumentException extends LogicException implements BaseException
+{
+}

From 3b19f06a50e0c15f102a1c21ab9967cd86d0ea82 Mon Sep 17 00:00:00 2001
From: kenjis <kenji.uui@gmail.com>
Date: Wed, 6 Jul 2022 11:52:21 +0900
Subject: [PATCH 5/8] refactor: use InvalidArgumentException

---
 src/Authentication/Authenticators/AccessTokens.php | 2 +-
 src/Authentication/Authenticators/Session.php      | 2 +-
 src/Models/UserModel.php                           | 3 +--
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/Authentication/Authenticators/AccessTokens.php b/src/Authentication/Authenticators/AccessTokens.php
index 1c6884475..3bf64f587 100644
--- a/src/Authentication/Authenticators/AccessTokens.php
+++ b/src/Authentication/Authenticators/AccessTokens.php
@@ -7,11 +7,11 @@
 use CodeIgniter\Shield\Authentication\AuthenticationException;
 use CodeIgniter\Shield\Authentication\AuthenticatorInterface;
 use CodeIgniter\Shield\Entities\User;
+use CodeIgniter\Shield\Exceptions\InvalidArgumentException;
 use CodeIgniter\Shield\Models\TokenLoginModel;
 use CodeIgniter\Shield\Models\UserIdentityModel;
 use CodeIgniter\Shield\Models\UserModel;
 use CodeIgniter\Shield\Result;
-use InvalidArgumentException;
 
 class AccessTokens implements AuthenticatorInterface
 {
diff --git a/src/Authentication/Authenticators/Session.php b/src/Authentication/Authenticators/Session.php
index 36b1fc464..919a5ccff 100644
--- a/src/Authentication/Authenticators/Session.php
+++ b/src/Authentication/Authenticators/Session.php
@@ -13,6 +13,7 @@
 use CodeIgniter\Shield\Authentication\Passwords;
 use CodeIgniter\Shield\Entities\User;
 use CodeIgniter\Shield\Entities\UserIdentity;
+use CodeIgniter\Shield\Exceptions\InvalidArgumentException;
 use CodeIgniter\Shield\Exceptions\LogicException;
 use CodeIgniter\Shield\Models\LoginModel;
 use CodeIgniter\Shield\Models\RememberModel;
@@ -20,7 +21,6 @@
 use CodeIgniter\Shield\Models\UserModel;
 use CodeIgniter\Shield\Result;
 use Exception;
-use InvalidArgumentException;
 use stdClass;
 
 class Session implements AuthenticatorInterface
diff --git a/src/Models/UserModel.php b/src/Models/UserModel.php
index 4cb80331d..bce426088 100644
--- a/src/Models/UserModel.php
+++ b/src/Models/UserModel.php
@@ -2,14 +2,13 @@
 
 namespace CodeIgniter\Shield\Models;
 
-use CodeIgniter\Database\Database;
 use CodeIgniter\Database\Exceptions\DataException;
 use CodeIgniter\Model;
 use CodeIgniter\Shield\Authentication\Authenticators\Session;
 use CodeIgniter\Shield\Entities\User;
+use CodeIgniter\Shield\Exceptions\InvalidArgumentException;
 use CodeIgniter\Shield\Exceptions\RuntimeException;
 use Faker\Generator;
-use InvalidArgumentException;
 
 class UserModel extends Model
 {

From 588d6faa8b08f4efd0762b92e0d20b7cf18d4d0b Mon Sep 17 00:00:00 2001
From: kenjis <kenji.uui@gmail.com>
Date: Wed, 6 Jul 2022 11:52:49 +0900
Subject: [PATCH 6/8] refactor: use RuntimeException

---
 src/Authorization/Groups.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Authorization/Groups.php b/src/Authorization/Groups.php
index b60a62062..9bbe99fdf 100644
--- a/src/Authorization/Groups.php
+++ b/src/Authorization/Groups.php
@@ -3,7 +3,7 @@
 namespace CodeIgniter\Shield\Authorization;
 
 use CodeIgniter\Shield\Entities\Group;
-use RuntimeException;
+use CodeIgniter\Shield\Exceptions\RuntimeException;
 
 /**
  * Provides utility feature for working with

From aa1a5cb529d2cd3b6c5cc62221850c6e369e1295 Mon Sep 17 00:00:00 2001
From: kenjis <kenji.uui@gmail.com>
Date: Wed, 6 Jul 2022 11:54:45 +0900
Subject: [PATCH 7/8] refactor: remove \Excetpion

It is not expected to catch these exceptions.
---
 src/Authentication/Authenticators/Session.php | 3 ---
 src/Models/LoginModel.php                     | 3 ---
 src/Models/TokenLoginModel.php                | 3 ---
 3 files changed, 9 deletions(-)

diff --git a/src/Authentication/Authenticators/Session.php b/src/Authentication/Authenticators/Session.php
index 919a5ccff..5f91f4c3e 100644
--- a/src/Authentication/Authenticators/Session.php
+++ b/src/Authentication/Authenticators/Session.php
@@ -20,7 +20,6 @@
 use CodeIgniter\Shield\Models\UserIdentityModel;
 use CodeIgniter\Shield\Models\UserModel;
 use CodeIgniter\Shield\Result;
-use Exception;
 use stdClass;
 
 class Session implements AuthenticatorInterface
@@ -812,8 +811,6 @@ public function recordActiveDate(): void
      * and stores the necessary info in the db and a cookie.
      *
      * @see https://paragonie.com/blog/2015/04/secure-authentication-php-with-long-term-persistence
-     *
-     * @throws Exception
      */
     protected function rememberUser(User $user): void
     {
diff --git a/src/Models/LoginModel.php b/src/Models/LoginModel.php
index 401a66e91..f36d91989 100644
--- a/src/Models/LoginModel.php
+++ b/src/Models/LoginModel.php
@@ -7,7 +7,6 @@
 use CodeIgniter\Shield\Authentication\Authenticators\Session;
 use CodeIgniter\Shield\Entities\Login;
 use CodeIgniter\Shield\Entities\User;
-use Exception;
 use Faker\Generator;
 
 class LoginModel extends Model
@@ -81,8 +80,6 @@ public function lastLogin(User $user): ?Login
 
     /**
      * Generate a fake login for testing
-     *
-     * @throws Exception
      */
     public function fake(Generator &$faker): Login
     {
diff --git a/src/Models/TokenLoginModel.php b/src/Models/TokenLoginModel.php
index fcb8dee25..1ab371b3d 100644
--- a/src/Models/TokenLoginModel.php
+++ b/src/Models/TokenLoginModel.php
@@ -4,7 +4,6 @@
 
 use CodeIgniter\I18n\Time;
 use CodeIgniter\Shield\Entities\Login;
-use Exception;
 use Faker\Generator;
 
 class TokenLoginModel extends LoginModel
@@ -13,8 +12,6 @@ class TokenLoginModel extends LoginModel
 
     /**
      * Generate a fake login for testing
-     *
-     * @throws Exception
      */
     public function fake(Generator &$faker): Login
     {

From d8342ddd381ea475d534df6e9e8aef6318866f29 Mon Sep 17 00:00:00 2001
From: kenjis <kenji.uui@gmail.com>
Date: Mon, 11 Jul 2022 16:21:27 +0900
Subject: [PATCH 8/8] fix: HTTPExcetpion is not needed

---
 src/Authentication/AuthenticationException.php  | 5 +++--
 src/Authentication/Passwords/PwnedValidator.php | 2 +-
 src/Authorization/AuthorizationException.php    | 4 ++--
 src/Exceptions/HTTPException.php                | 9 ---------
 tests/Unit/PwnedValidatorTest.php               | 2 +-
 5 files changed, 7 insertions(+), 15 deletions(-)
 delete mode 100644 src/Exceptions/HTTPException.php

diff --git a/src/Authentication/AuthenticationException.php b/src/Authentication/AuthenticationException.php
index 219e05d3a..75806ebf2 100644
--- a/src/Authentication/AuthenticationException.php
+++ b/src/Authentication/AuthenticationException.php
@@ -2,9 +2,10 @@
 
 namespace CodeIgniter\Shield\Authentication;
 
-use CodeIgniter\Shield\Exceptions\HTTPException;
+use CodeIgniter\HTTP\Exceptions\HTTPException;
+use CodeIgniter\Shield\Exceptions\RuntimeException;
 
-class AuthenticationException extends HTTPException
+class AuthenticationException extends RuntimeException
 {
     protected $code = 403;
 
diff --git a/src/Authentication/Passwords/PwnedValidator.php b/src/Authentication/Passwords/PwnedValidator.php
index 8e0587f7e..d643b4b20 100644
--- a/src/Authentication/Passwords/PwnedValidator.php
+++ b/src/Authentication/Passwords/PwnedValidator.php
@@ -3,9 +3,9 @@
 namespace CodeIgniter\Shield\Authentication\Passwords;
 
 use CodeIgniter\Config\Services;
+use CodeIgniter\HTTP\Exceptions\HTTPException;
 use CodeIgniter\Shield\Authentication\AuthenticationException;
 use CodeIgniter\Shield\Entities\User;
-use CodeIgniter\Shield\Exceptions\HTTPException;
 use CodeIgniter\Shield\Result;
 
 /**
diff --git a/src/Authorization/AuthorizationException.php b/src/Authorization/AuthorizationException.php
index 62c4d98e3..337976a17 100644
--- a/src/Authorization/AuthorizationException.php
+++ b/src/Authorization/AuthorizationException.php
@@ -2,9 +2,9 @@
 
 namespace CodeIgniter\Shield\Authorization;
 
-use CodeIgniter\Shield\Exceptions\HTTPException;
+use CodeIgniter\Shield\Exceptions\RuntimeException;
 
-class AuthorizationException extends HTTPException
+class AuthorizationException extends RuntimeException
 {
     protected $code = 401;
 
diff --git a/src/Exceptions/HTTPException.php b/src/Exceptions/HTTPException.php
deleted file mode 100644
index 157673bc1..000000000
--- a/src/Exceptions/HTTPException.php
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-
-namespace CodeIgniter\Shield\Exceptions;
-
-use CodeIgniter\HTTP\Exceptions\HTTPException as FrameworkHTTPException;
-
-class HTTPException extends FrameworkHTTPException implements BaseException
-{
-}
diff --git a/tests/Unit/PwnedValidatorTest.php b/tests/Unit/PwnedValidatorTest.php
index 77038ff93..b303b3389 100644
--- a/tests/Unit/PwnedValidatorTest.php
+++ b/tests/Unit/PwnedValidatorTest.php
@@ -2,12 +2,12 @@
 
 namespace Tests\Unit;
 
+use CodeIgniter\HTTP\Exceptions\HTTPException;
 use CodeIgniter\HTTP\Response;
 use CodeIgniter\Shield\Authentication\AuthenticationException;
 use CodeIgniter\Shield\Authentication\Passwords\PwnedValidator;
 use CodeIgniter\Shield\Config\Auth as AuthConfig;
 use CodeIgniter\Shield\Config\Services;
-use CodeIgniter\Shield\Exceptions\HTTPException;
 use CodeIgniter\Test\CIUnitTestCase;
 use Config\App;