Skip to content

Commit

Permalink
Merge pull request #286 from kenjis/fix-exception-structure
Browse files Browse the repository at this point in the history
fix: Exception structure
  • Loading branch information
kenjis authored Jul 15, 2022
2 parents 794275f + d8342dd commit dadd7b3
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Authentication/AuthenticationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace CodeIgniter\Shield\Authentication;

use CodeIgniter\HTTP\Exceptions\HTTPException;
use Exception;
use CodeIgniter\Shield\Exceptions\RuntimeException;

class AuthenticationException extends Exception
class AuthenticationException extends RuntimeException
{
protected $code = 403;

Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/Authenticators/AccessTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 1 addition & 4 deletions src/Authentication/Authenticators/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
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;
use CodeIgniter\Shield\Models\UserIdentityModel;
use CodeIgniter\Shield\Models\UserModel;
use CodeIgniter\Shield\Result;
use Exception;
use InvalidArgumentException;
use stdClass;

class Session implements AuthenticatorInterface
Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions src/Authorization/AuthorizationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace CodeIgniter\Shield\Authorization;

use Exception;
use CodeIgniter\Shield\Exceptions\RuntimeException;

class AuthorizationException extends Exception
class AuthorizationException extends RuntimeException
{
protected $code = 401;

Expand Down
2 changes: 1 addition & 1 deletion src/Authorization/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/Exceptions/BaseException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace CodeIgniter\Shield\Exceptions;

use Throwable;

/**
* Base Exception Interface for Shield
*/
interface BaseException extends Throwable
{
}
7 changes: 7 additions & 0 deletions src/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace CodeIgniter\Shield\Exceptions;

class InvalidArgumentException extends LogicException implements BaseException
{
}
2 changes: 1 addition & 1 deletion src/Exceptions/LogicException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace CodeIgniter\Shield\Exceptions;

class LogicException extends \LogicException
class LogicException extends \LogicException implements BaseException
{
}
2 changes: 1 addition & 1 deletion src/Exceptions/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace CodeIgniter\Shield\Exceptions;

class RuntimeException extends \RuntimeException
class RuntimeException extends \RuntimeException implements BaseException
{
}
3 changes: 0 additions & 3 deletions src/Models/LoginModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,8 +80,6 @@ public function lastLogin(User $user): ?Login

/**
* Generate a fake login for testing
*
* @throws Exception
*/
public function fake(Generator &$faker): Login
{
Expand Down
3 changes: 0 additions & 3 deletions src/Models/TokenLoginModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use CodeIgniter\I18n\Time;
use CodeIgniter\Shield\Entities\Login;
use Exception;
use Faker\Generator;

class TokenLoginModel extends LoginModel
Expand All @@ -13,8 +12,6 @@ class TokenLoginModel extends LoginModel

/**
* Generate a fake login for testing
*
* @throws Exception
*/
public function fake(Generator &$faker): Login
{
Expand Down
3 changes: 1 addition & 2 deletions src/Models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit dadd7b3

Please sign in to comment.