Skip to content

Commit ffb38bb

Browse files
committed
refactor: improve readability and consistency in BoostServiceProvider
- Update docblock annotations for clarity. - Merge `match` statement cases for concise handling. - Adjust visibility of `registerBladeDirectives` to private.
1 parent 1ae687d commit ffb38bb

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/BoostServiceProvider.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
88
use Illuminate\Http\Request;
9+
use Illuminate\Log\Logger;
910
use Illuminate\Routing\Router;
1011
use Illuminate\Support\Facades\Log;
1112
use Illuminate\Support\Facades\Route;
@@ -69,7 +70,7 @@ public function boot(Router $router): void
6970
$this->hookIntoResponses($router);
7071
}
7172

72-
protected function registerPublishing(): void
73+
private function registerPublishing(): void
7374
{
7475
if ($this->app->runningInConsole()) {
7576
$this->publishes([
@@ -78,7 +79,7 @@ protected function registerPublishing(): void
7879
}
7980
}
8081

81-
protected function registerCommands(): void
82+
private function registerCommands(): void
8283
{
8384
if ($this->app->runningInConsole()) {
8485
$this->commands([
@@ -93,14 +94,14 @@ private function registerRoutes(): void
9394
{
9495
Route::post('/_boost/browser-logs', function (Request $request) {
9596
$logs = $request->input('logs', []);
96-
/** @var \Illuminate\Log\Logger $logger */
97+
/** @var Logger $logger */
9798
$logger = Log::channel('browser');
9899

99100
/**
100101
* @var array{
101102
* type: 'error'|'warn'|'info'|'log'|'table'|'window_error'|'uncaught_error'|'unhandled_rejection',
102103
* timestamp: string,
103-
* data: array<mixed>,
104+
* data: array,
104105
* url:string,
105106
* userAgent:string
106107
* } $log */
@@ -123,13 +124,13 @@ private function registerRoutes(): void
123124
}
124125

125126
/**
126-
* Build a string message for the log based on various input types. Single dimensional, and multi:
127-
* "data":[
128-
* {"message":"Unhandled Promise Rejection","reason":{"name":"TypeError","message":"NetworkError when attempting to fetch resource.","stack":""}}]
127+
* Build a string message for the log based on various input types. Single-dimensional, and multi:
128+
* "data": {"message":"Unhandled Promise Rejection","reason":{"name":"TypeError","message":"NetworkError when attempting to fetch resource.","stack":""}}]
129129
*
130-
* @param array<mixed> $data
130+
* @param array $data
131+
* @return string
131132
*/
132-
protected function buildLogMessageFromData(array $data): string
133+
private function buildLogMessageFromData(array $data): string
133134
{
134135
$messages = [];
135136

@@ -146,7 +147,7 @@ protected function buildLogMessageFromData(array $data): string
146147
return implode(' ', $messages);
147148
}
148149

149-
protected function registerBrowserLogger(): void
150+
private function registerBrowserLogger(): void
150151
{
151152
config([
152153
'logging.channels.browser' => [
@@ -158,7 +159,7 @@ protected function registerBrowserLogger(): void
158159
]);
159160
}
160161

161-
protected function registerBladeDirectives(BladeCompiler $bladeCompiler): void
162+
private function registerBladeDirectives(BladeCompiler $bladeCompiler): void
162163
{
163164
$bladeCompiler->directive('boostJs', fn () => '<?php echo \\Laravel\\Boost\\Services\\BrowserLogger::getScript(); ?>');
164165
}
@@ -167,11 +168,8 @@ private function mapJsTypeToPsr3Level(string $type): string
167168
{
168169
return match ($type) {
169170
'warn' => 'warning',
170-
'log' => 'debug',
171-
'table' => 'debug',
172-
'window_error' => 'error',
173-
'uncaught_error' => 'error',
174-
'unhandled_rejection' => 'error',
171+
'log', 'table' => 'debug',
172+
'window_error', 'uncaught_error', 'unhandled_rejection' => 'error',
175173
default => $type
176174
};
177175
}

0 commit comments

Comments
 (0)