Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| JsErrorLogController | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| log | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Web\Controller; |
| 6 | |
| 7 | use App\Shared\Logging\CentralLogger; |
| 8 | use Psr\Http\Message\ResponseFactoryInterface; |
| 9 | use Psr\Http\Message\ResponseInterface; |
| 10 | use Psr\Http\Message\ServerRequestInterface; |
| 11 | |
| 12 | class JsErrorLogController |
| 13 | { |
| 14 | public function __construct(private ResponseFactoryInterface $responseFactory) {} |
| 15 | |
| 16 | public function log(ServerRequestInterface $request): ResponseInterface |
| 17 | { |
| 18 | /** @var array<string, mixed> $body */ |
| 19 | $body = (array) ($request->getParsedBody() ?? []); |
| 20 | |
| 21 | CentralLogger::logJsError([ |
| 22 | 'message' => is_string($body['message'] ?? null) ? (string) $body['message'] : 'Client JS Error', |
| 23 | 'url' => is_string($body['url'] ?? null) ? (string) $body['url'] : 'Unknown URL', |
| 24 | 'line' => is_numeric($body['line'] ?? null) ? (int) $body['line'] : 0, |
| 25 | 'column' => is_numeric($body['column'] ?? null) ? (int) $body['column'] : 0, |
| 26 | 'stack' => is_string($body['stack'] ?? null) ? (string) $body['stack'] : '', |
| 27 | ]); |
| 28 | |
| 29 | $response = $this->responseFactory->createResponse(200) |
| 30 | ->withHeader('Content-Type', 'application/json'); |
| 31 | $response->getBody()->write((string) json_encode(['status' => 'logged'])); |
| 32 | |
| 33 | return $response; |
| 34 | } |
| 35 | } |