Skip to content

Commit 21d035a

Browse files
committed
refactor: cleanup Exceptions
1 parent 5c78ba2 commit 21d035a

File tree

9 files changed

+89
-603
lines changed

9 files changed

+89
-603
lines changed

.github/workflows/test-file-permissions.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ jobs:
2020
- name: Checkout
2121
uses: actions/checkout@v6
2222

23+
- name: Setup PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: '8.2'
27+
2328
- name: Detect unnecessary execution permissions
2429
run: php utils/check_permission_x.php

.github/workflows/test-userguide.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ jobs:
2626
- name: Checkout
2727
uses: actions/checkout@v6
2828

29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: '8.2'
33+
2934
- name: Setup Python
3035
uses: actions/setup-python@v6
3136
with:

system/Debug/BaseExceptionHandler.php

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313

1414
namespace CodeIgniter\Debug;
1515

16-
use CodeIgniter\HTTP\CLIRequest;
17-
use CodeIgniter\HTTP\IncomingRequest;
18-
use CodeIgniter\HTTP\RequestInterface;
19-
use CodeIgniter\HTTP\ResponseInterface;
2016
use Config\Exceptions as ExceptionsConfig;
2117
use Throwable;
2218

@@ -53,21 +49,6 @@ public function __construct(ExceptionsConfig $config)
5349
}
5450
}
5551

56-
/**
57-
* The main entry point into the handler.
58-
*
59-
* @param CLIRequest|IncomingRequest $request
60-
*
61-
* @return void
62-
*/
63-
abstract public function handle(
64-
Throwable $exception,
65-
RequestInterface $request,
66-
ResponseInterface $response,
67-
int $statusCode,
68-
int $exitCode,
69-
);
70-
7152
/**
7253
* Gathers the variables that will be made available to the view.
7354
*/
@@ -76,7 +57,7 @@ protected function collectVars(Throwable $exception, int $statusCode): array
7657
// Get the first exception.
7758
$firstException = $exception;
7859

79-
while ($prevException = $firstException->getPrevious()) {
60+
while (($prevException = $firstException->getPrevious()) instanceof Throwable) {
8061
$firstException = $prevException;
8162
}
8263

@@ -110,17 +91,18 @@ protected function maskSensitiveData(array $trace, array $keysToMask, string $pa
11091
}
11192

11293
/**
113-
* @param array|object $args
94+
* @param array<string, mixed>|object $args
95+
* @param array<int, string> $keysToMask
11496
*
115-
* @return array|object
97+
* @return array<string, mixed>|object
11698
*/
117-
private function maskData($args, array $keysToMask, string $path = '')
99+
private function maskData(array|object $args, array $keysToMask, string $path = ''): array|object
118100
{
119-
foreach ($keysToMask as $keyToMask) {
120-
$explode = explode('/', $keyToMask);
101+
foreach ($keysToMask as $key) {
102+
$explode = explode('/', $key);
121103
$index = end($explode);
122104

123-
if (str_starts_with(strrev($path . '/' . $index), strrev($keyToMask))) {
105+
if (str_starts_with(strrev($path . '/' . $index), strrev($key))) {
124106
if (is_array($args) && array_key_exists($index, $args)) {
125107
$args[$index] = '******************';
126108
} elseif (
@@ -136,7 +118,7 @@ private function maskData($args, array $keysToMask, string $path = '')
136118
foreach ($args as $pathKey => $subarray) {
137119
$args[$pathKey] = $this->maskData($subarray, $keysToMask, $path . '/' . $pathKey);
138120
}
139-
} elseif (is_object($args)) {
121+
} else {
140122
foreach ($args as $pathKey => $subarray) {
141123
$args->{$pathKey} = $this->maskData($subarray, $keysToMask, $path . '/' . $pathKey);
142124
}

system/Debug/ExceptionHandler.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ public function handle(
9595
$this->respond($data, $statusCode)->send();
9696

9797
if (ENVIRONMENT !== 'testing') {
98-
// @codeCoverageIgnoreStart
99-
exit($exitCode);
100-
// @codeCoverageIgnoreEnd
98+
exit($exitCode); // @codeCoverageIgnore
10199
}
102100

103101
return;
@@ -126,9 +124,7 @@ public function handle(
126124
$this->render($exception, $statusCode, $viewFile);
127125

128126
if (ENVIRONMENT !== 'testing') {
129-
// @codeCoverageIgnoreStart
130-
exit($exitCode);
131-
// @codeCoverageIgnoreEnd
127+
exit($exitCode); // @codeCoverageIgnore
132128
}
133129
}
134130

0 commit comments

Comments
 (0)