Skip to content

Commit 3bac9cb

Browse files
committed
feat: rename ExitExceptionInterface and add getExitCode()
1 parent dc51f1e commit 3bac9cb

File tree

6 files changed

+30
-34
lines changed

6 files changed

+30
-34
lines changed

system/Database/Exceptions/DatabaseException.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111

1212
namespace CodeIgniter\Database\Exceptions;
1313

14-
use CodeIgniter\Exceptions\ExitExceptionInterface;
14+
use CodeIgniter\Exceptions\HasExitCodeInterface;
1515
use Error;
1616

17-
class DatabaseException extends Error implements ExceptionInterface, ExitExceptionInterface
17+
class DatabaseException extends Error implements ExceptionInterface, HasExitCodeInterface
1818
{
19-
/**
20-
* Exit status code
21-
*
22-
* @var int
23-
*/
24-
protected $code = EXIT_DATABASE;
19+
public function getExitCode(): int
20+
{
21+
return EXIT_DATABASE;
22+
}
2523
}

system/Debug/Exceptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace CodeIgniter\Debug;
1313

1414
use CodeIgniter\API\ResponseTrait;
15-
use CodeIgniter\Exceptions\ExitExceptionInterface;
15+
use CodeIgniter\Exceptions\HasExitCodeInterface;
1616
use CodeIgniter\Exceptions\HTTPExceptionInterface;
1717
use CodeIgniter\Exceptions\PageNotFoundException;
1818
use CodeIgniter\HTTP\CLIRequest;
@@ -321,8 +321,8 @@ protected function determineCodes(Throwable $exception): array
321321
$statusCode = $exception->getCode();
322322
}
323323

324-
if ($exception instanceof ExitExceptionInterface) {
325-
$exitStatus = $exception->getCode();
324+
if ($exception instanceof HasExitCodeInterface) {
325+
$exitStatus = $exception->getExitCode();
326326
}
327327

328328
return [$statusCode, $exitStatus];

system/Entity/Exceptions/CastException.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,18 @@
1111

1212
namespace CodeIgniter\Entity\Exceptions;
1313

14-
use CodeIgniter\Exceptions\ExitExceptionInterface;
1514
use CodeIgniter\Exceptions\FrameworkException;
15+
use CodeIgniter\Exceptions\HasExitCodeInterface;
1616

1717
/**
1818
* CastException is thrown for invalid cast initialization and management.
1919
*/
20-
class CastException extends FrameworkException implements ExitExceptionInterface
20+
class CastException extends FrameworkException implements HasExitCodeInterface
2121
{
22-
/**
23-
* Exit status code
24-
*
25-
* @var int
26-
*/
27-
protected $code = EXIT_CONFIG;
22+
public function getExitCode(): int
23+
{
24+
return EXIT_CONFIG;
25+
}
2826

2927
/**
3028
* Thrown when the cast class does not extends BaseCast.

system/Exceptions/CastException.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818
*
1919
* @codeCoverageIgnore
2020
*/
21-
class CastException extends CriticalError implements ExitExceptionInterface
21+
class CastException extends CriticalError implements HasExitCodeInterface
2222
{
2323
use DebugTraceableTrait;
2424

25-
/**
26-
* Exit status code
27-
*
28-
* @var int
29-
*/
30-
protected $code = EXIT_CONFIG;
25+
public function getExitCode(): int
26+
{
27+
return EXIT_CONFIG;
28+
}
3129

3230
public static function forInvalidJsonFormatException(int $error)
3331
{

system/Exceptions/ConfigException.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414
/**
1515
* Exception for automatic logging.
1616
*/
17-
class ConfigException extends CriticalError implements ExitExceptionInterface
17+
class ConfigException extends CriticalError implements HasExitCodeInterface
1818
{
1919
use DebugTraceableTrait;
2020

21-
/**
22-
* Exit status code
23-
*
24-
* @var int
25-
*/
26-
protected $code = EXIT_CONFIG;
21+
public function getExitCode(): int
22+
{
23+
return EXIT_CONFIG;
24+
}
2725

2826
public static function forDisabledMigrations()
2927
{

system/Exceptions/ExitExceptionInterface.php renamed to system/Exceptions/HasExitCodeInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
/**
1515
* Interface for Exceptions that has exception code as exit code.
1616
*/
17-
interface ExitExceptionInterface
17+
interface HasExitCodeInterface
1818
{
19+
/**
20+
* Returns exit status code.
21+
*/
22+
public function getExitCode(): int;
1923
}

0 commit comments

Comments
 (0)