Skip to content

Commit 0096698

Browse files
committed
refactor: cleanup Exceptions
1 parent f1e8bdd commit 0096698

File tree

9 files changed

+71
-588
lines changed

9 files changed

+71
-588
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: 7 additions & 28 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

@@ -103,24 +84,22 @@ protected function collectVars(Throwable $exception, int $statusCode): array
10384
protected function maskSensitiveData(array $trace, array $keysToMask, string $path = ''): array
10485
{
10586
foreach ($trace as $i => $line) {
106-
$trace[$i]['args'] = $this->maskData($line['args'], $keysToMask);
87+
$trace[$i]['args'] = $this->maskData($line['args'], $keysToMask, $path);
10788
}
10889

10990
return $trace;
11091
}
11192

11293
/**
113-
* @param array|object $args
114-
*
115-
* @return array|object
94+
* @param array<int, string> $keysToMask
11695
*/
117-
private function maskData($args, array $keysToMask, string $path = '')
96+
private function maskData(mixed $args, array $keysToMask, string $path = ''): mixed
11897
{
119-
foreach ($keysToMask as $keyToMask) {
120-
$explode = explode('/', $keyToMask);
98+
foreach ($keysToMask as $key) {
99+
$explode = explode('/', $key);
121100
$index = end($explode);
122101

123-
if (str_starts_with(strrev($path . '/' . $index), strrev($keyToMask))) {
102+
if (str_starts_with(strrev($path . '/' . $index), strrev($key))) {
124103
if (is_array($args) && array_key_exists($index, $args)) {
125104
$args[$index] = '******************';
126105
} elseif (

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)