Skip to content

Commit 04eb873

Browse files
committed
refactor(collectors): Standardize keys in collector arrays
- Capitalize the keys in the collected data arrays for consistency - Update keys in ApplicationCollector, ExceptionBasicCollector, RequestBasicCollector, and RequestFileCollector - Improve readability and maintainability of collector output
1 parent 984d150 commit 04eb873

File tree

6 files changed

+49
-47
lines changed

6 files changed

+49
-47
lines changed

src/Collectors/ApplicationCollector.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ public function __construct(
2929
public function collect(): array
3030
{
3131
return [
32-
'time' => Carbon::now()->format('Y-m-d H:i:s'),
33-
'name' => config('app.name'),
34-
'version' => $this->container->version(),
35-
'php version' => \PHP_VERSION,
36-
'environment' => $this->container->environment(),
37-
'debug' => $this->container->hasDebugModeEnabled(),
38-
'in console' => $this->container->runningInConsole(),
32+
'Time' => Carbon::now()->format('Y-m-d H:i:s'),
33+
'Name' => config('app.name'),
34+
'Version' => $this->container->version(),
35+
'PHP Version' => \PHP_VERSION,
36+
'Environment' => $this->container->environment(),
37+
'In Console' => $this->container->runningInConsole(),
38+
'Debug Mode' => $this->container->hasDebugModeEnabled(),
39+
'Maintenance Mode' => $this->container->isDownForMaintenance(),
3940
];
4041
}
4142
}

src/Collectors/ExceptionBasicCollector.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class ExceptionBasicCollector extends AbstractExceptionCollector
2121
public function collect(): array
2222
{
2323
return [
24-
'message' => $this->exception->getMessage(),
25-
'code' => $this->exception->getCode(),
26-
'class' => $this->exception::class,
27-
'file' => $this->exception->getFile(),
28-
'line' => $this->exception->getLine(),
24+
'Message' => $this->exception->getMessage(),
25+
'Code' => $this->exception->getCode(),
26+
'Class' => $this->exception::class,
27+
'File' => $this->exception->getFile(),
28+
'Line' => $this->exception->getLine(),
2929
];
3030
}
3131
}

src/Collectors/RequestBasicCollector.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public function __construct(private Request $request) {}
2323
public function collect(): array
2424
{
2525
return [
26-
'url' => $this->request->url(),
27-
'ip' => $this->request->ip(),
28-
'method' => $this->request->method(),
29-
'controller action' => $this->request->route()?->getActionName(),
30-
'memory' => Utils::humanBytes(memory_get_peak_usage(true)),
31-
'duration' => blank($startTime = \defined('LARAVEL_START') ? LARAVEL_START : $this->request->server('REQUEST_TIME_FLOAT'))
32-
? 'Unknown'
33-
: Utils::humanMilliseconds((microtime(true) - $startTime) * 1000),
26+
'URL' => $this->request->url(),
27+
'IP' => $this->request->ip(),
28+
'Method' => $this->request->method(),
29+
'Controller Action' => $this->request->route()?->getActionName(),
30+
'Memory' => Utils::humanBytes(memory_get_peak_usage(true)),
31+
'Duration' => blank(
32+
$startTime = \defined('LARAVEL_START') ? LARAVEL_START : $this->request->server('REQUEST_TIME_FLOAT')
33+
) ? 'Unknown' : Utils::humanMilliseconds((microtime(true) - $startTime) * 1000),
3434
];
3535
}
3636
}

src/Collectors/RequestFileCollector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public function collect(): array
3030

3131
array_walk_recursive($files, static function (UploadedFile &$uploadedFile): void {
3232
$uploadedFile = [
33-
'name' => $uploadedFile->getClientOriginalName(),
34-
'type' => $uploadedFile->getMimeType(),
35-
'error' => $uploadedFile->getError(),
36-
'size' => Utils::humanBytes($uploadedFile->getSize()),
33+
'Name' => $uploadedFile->getClientOriginalName(),
34+
'Type' => $uploadedFile->getMimeType(),
35+
'Error' => $uploadedFile->getError(),
36+
'Size' => Utils::humanBytes($uploadedFile->getSize()),
3737
];
3838
});
3939

src/Pipes/AddKeywordChorePipe.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AddKeywordChorePipe extends AddChorePipe
2121
{
2222
use WithPipeArgs;
2323

24-
public function handle(Collection $collectors, \Closure $next, mixed $value, mixed $key = 'keyword'): Stringable
24+
public function handle(Collection $collectors, \Closure $next, mixed $value, mixed $key = 'Keyword'): Stringable
2525
{
2626
return parent::handle($collectors, $next, $value, $key);
2727
}

tests/__snapshots__/FeatureTest__it_can_proactive_report_exception__1.json

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
22
"Application": {
3-
"time": "2025-03-23 06:28:50",
4-
"name": "Laravel",
5-
"version": "9.52.20",
6-
"php version": "8.0.30",
7-
"environment": "testing",
8-
"debug": false,
9-
"in console": true
3+
"Time": "2025-03-23 10:07:18",
4+
"Name": "Laravel",
5+
"Version": "9.52.20",
6+
"PHP Version": "8.0.30",
7+
"Environment": "testing",
8+
"In Console": true,
9+
"Debug Mode": false,
10+
"Maintenance Mode": false
1011
},
1112
"Chore": {},
1213
"Exception Basic": {
13-
"message": "What happened?",
14-
"code": 0,
15-
"class": "Guanguans\\LaravelExceptionNotify\\Exceptions\\RuntimeException",
16-
"file": "\/Users\/yaozm\/Documents\/develop\/laravel-exception-notify\/tests\/TestCase.php",
17-
"line": 171
14+
"Message": "What happened?",
15+
"Code": 0,
16+
"Class": "Guanguans\\LaravelExceptionNotify\\Exceptions\\RuntimeException",
17+
"File": "\/Users\/yaozm\/Documents\/develop\/laravel-exception-notify\/tests\/TestCase.php",
18+
"Line": 171
1819
},
1920
"Exception Context": {
2021
" 167": " assertMatchesJsonSnapshot($reportingEvent->content);\n",
@@ -35,19 +36,19 @@
3536
"49": "#49 {main}"
3637
},
3738
"Request Basic": {
38-
"url": "http:\/\/localhost\/proactive-report-exception",
39-
"ip": "127.0.0.1",
40-
"method": "POST",
41-
"controller action": "Closure",
42-
"memory": "50.50 MB",
43-
"duration": "13.81 ms"
39+
"URL": "http:\/\/localhost\/proactive-report-exception",
40+
"IP": "127.0.0.1",
41+
"Method": "POST",
42+
"Controller Action": "Closure",
43+
"Memory": "52.50 MB",
44+
"Duration": "19.94 ms"
4445
},
4546
"Request File": {
4647
"file": {
47-
"name": "FeatureTest.php",
48-
"type": "text\/x-php",
49-
"error": 0,
50-
"size": "1.27 KB"
48+
"Name": "FeatureTest.php",
49+
"Type": "text\/x-php",
50+
"Error": 0,
51+
"Size": "1.27 KB"
5152
}
5253
},
5354
"Request Header": {

0 commit comments

Comments
 (0)