From fd2a2a6123ac30b3d37e5feb0725ca081bd311be Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 10 Jan 2025 22:05:19 +0100 Subject: [PATCH] wip --- src/GithubIssueFormatter.php | 16 ++++++++-------- tests/GithubIssueFormatterTest.php | 4 ++-- tests/GithubIssueLoggerHandlerTest.php | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/GithubIssueFormatter.php b/src/GithubIssueFormatter.php index c7250ff..7a543f3 100644 --- a/src/GithubIssueFormatter.php +++ b/src/GithubIssueFormatter.php @@ -54,7 +54,7 @@ public function formatBatch(array $records): array private function generateSignature(LogRecord $record, ?Throwable $exception): string { if (! $exception) { - return md5($record->message.json_encode($record->context)); + return md5($record->message . json_encode($record->context)); } $trace = $exception->getTrace(); @@ -64,7 +64,7 @@ private function generateSignature(LogRecord $record, ?Throwable $exception): st $exception::class, $exception->getFile(), $exception->getLine(), - $firstFrame ? ($firstFrame['file'] ?? '').':'.($firstFrame['line'] ?? '') : '', + $firstFrame ? ($firstFrame['file'] ?? '') . ':' . ($firstFrame['line'] ?? '') : '', ])); } @@ -110,7 +110,7 @@ private function formatTitle(LogRecord $record, ?Throwable $exception = null): s private function formatContent(LogRecord $record, ?Throwable $exception): string { return Str::of('') - ->when($record->message, fn ($str, $message) => $str->append("**Message:**\n{$message}\n\n")) + ->when($record->message, fn($str, $message) => $str->append("**Message:**\n{$message}\n\n")) ->when( $exception, function (Stringable $str, Throwable $exception) { @@ -120,8 +120,8 @@ function (Stringable $str, Throwable $exception) { ); } ) - ->when(! $exception && ! empty($record->context), fn ($str, $context) => $str->append("**Context:**\n```json\n{$context}\n```\n\n")) - ->when(! empty($record->extra), fn ($str, $extra) => $str->append("**Extra Data:**\n```json\n{$extra}\n```\n")) + ->when(!$exception && !empty($record->context), fn($str, $context) => $str->append("**Context:**\n```json\n" . json_encode($record->context, JSON_PRETTY_PRINT) . "\n```\n\n")) + ->when(!empty($record->extra), fn($str, $extra) => $str->append("**Extra Data:**\n```json\n" . json_encode($record->extra, JSON_PRETTY_PRINT) . "\n```\n")) ->toString(); } @@ -141,7 +141,7 @@ private function formatBody(LogRecord $record, string $signature, ?Throwable $ex private function cleanStackTrace(string $stackTrace): string { return collect(explode("\n", $stackTrace)) - ->filter(fn ($line) => ! empty(trim($line))) + ->filter(fn($line) => ! empty(trim($line))) ->map(function ($line) { if (trim($line) === '"}') { return ''; @@ -217,8 +217,8 @@ private function formatExceptionDetails(Throwable $exception): array return [ 'message' => $exception->getMessage(), - 'stack_trace' => $header."\n[stacktrace]\n".$this->cleanStackTrace($exception->getTraceAsString()), - 'full_stack_trace' => $header."\n[stacktrace]\n".$exception->getTraceAsString(), + 'stack_trace' => $header . "\n[stacktrace]\n" . $this->cleanStackTrace($exception->getTraceAsString()), + 'full_stack_trace' => $header . "\n[stacktrace]\n" . $exception->getTraceAsString(), ]; } diff --git a/tests/GithubIssueFormatterTest.php b/tests/GithubIssueFormatterTest.php index f81d79c..45c0a6b 100644 --- a/tests/GithubIssueFormatterTest.php +++ b/tests/GithubIssueFormatterTest.php @@ -78,8 +78,8 @@ $formatted = $formatter->format($record); expect($formatted->body) - ->toContain('"user_id":123') - ->toContain('"action":"login"'); + ->toContain('"user_id": 123') + ->toContain('"action": "login"'); }); test('it generates consistent signatures for similar errors', function () { diff --git a/tests/GithubIssueLoggerHandlerTest.php b/tests/GithubIssueLoggerHandlerTest.php index 486348f..527740a 100644 --- a/tests/GithubIssueLoggerHandlerTest.php +++ b/tests/GithubIssueLoggerHandlerTest.php @@ -186,8 +186,8 @@ function createFormattedRecord(GithubIssueLoggerHandler $handler, string $messag Http::assertSent(function ($request) { return $request->url() === 'https://api.github.com/repos/test/repo/issues' && - str_contains($request['body'], '"server":"production"') && - str_contains($request['body'], '"user_id":123'); + str_contains($request['body'], '"server": "production"') && + str_contains($request['body'], '"user_id": 123'); }); });