Skip to content

Commit

Permalink
feat: rename ExitExceptionInterface and add getExitCode()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 24, 2022
1 parent dc51f1e commit 3bac9cb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
14 changes: 6 additions & 8 deletions system/Database/Exceptions/DatabaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@

namespace CodeIgniter\Database\Exceptions;

use CodeIgniter\Exceptions\ExitExceptionInterface;
use CodeIgniter\Exceptions\HasExitCodeInterface;
use Error;

class DatabaseException extends Error implements ExceptionInterface, ExitExceptionInterface
class DatabaseException extends Error implements ExceptionInterface, HasExitCodeInterface
{
/**
* Exit status code
*
* @var int
*/
protected $code = EXIT_DATABASE;
public function getExitCode(): int
{
return EXIT_DATABASE;
}
}
6 changes: 3 additions & 3 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace CodeIgniter\Debug;

use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Exceptions\ExitExceptionInterface;
use CodeIgniter\Exceptions\HasExitCodeInterface;
use CodeIgniter\Exceptions\HTTPExceptionInterface;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\CLIRequest;
Expand Down Expand Up @@ -321,8 +321,8 @@ protected function determineCodes(Throwable $exception): array
$statusCode = $exception->getCode();
}

if ($exception instanceof ExitExceptionInterface) {
$exitStatus = $exception->getCode();
if ($exception instanceof HasExitCodeInterface) {
$exitStatus = $exception->getExitCode();
}

return [$statusCode, $exitStatus];
Expand Down
14 changes: 6 additions & 8 deletions system/Entity/Exceptions/CastException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@

namespace CodeIgniter\Entity\Exceptions;

use CodeIgniter\Exceptions\ExitExceptionInterface;
use CodeIgniter\Exceptions\FrameworkException;
use CodeIgniter\Exceptions\HasExitCodeInterface;

/**
* CastException is thrown for invalid cast initialization and management.
*/
class CastException extends FrameworkException implements ExitExceptionInterface
class CastException extends FrameworkException implements HasExitCodeInterface
{
/**
* Exit status code
*
* @var int
*/
protected $code = EXIT_CONFIG;
public function getExitCode(): int
{
return EXIT_CONFIG;
}

/**
* Thrown when the cast class does not extends BaseCast.
Expand Down
12 changes: 5 additions & 7 deletions system/Exceptions/CastException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
*
* @codeCoverageIgnore
*/
class CastException extends CriticalError implements ExitExceptionInterface
class CastException extends CriticalError implements HasExitCodeInterface
{
use DebugTraceableTrait;

/**
* Exit status code
*
* @var int
*/
protected $code = EXIT_CONFIG;
public function getExitCode(): int
{
return EXIT_CONFIG;
}

public static function forInvalidJsonFormatException(int $error)
{
Expand Down
12 changes: 5 additions & 7 deletions system/Exceptions/ConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
/**
* Exception for automatic logging.
*/
class ConfigException extends CriticalError implements ExitExceptionInterface
class ConfigException extends CriticalError implements HasExitCodeInterface
{
use DebugTraceableTrait;

/**
* Exit status code
*
* @var int
*/
protected $code = EXIT_CONFIG;
public function getExitCode(): int
{
return EXIT_CONFIG;
}

public static function forDisabledMigrations()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
/**
* Interface for Exceptions that has exception code as exit code.
*/
interface ExitExceptionInterface
interface HasExitCodeInterface
{
/**
* Returns exit status code.
*/
public function getExitCode(): int;
}

0 comments on commit 3bac9cb

Please sign in to comment.