Lines 100.00% 7 / 7
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 process 100.00% 6 / 6 100.00% 1 / 1 2
16class RequestLoggingMiddleware implements MiddlewareInterface
17{
18    private LoggerService $logger;
19
20    public function __construct(LoggerService $logger)
21    {
22        $this->logger = $logger;
23    }
24
25    /**
26     * Process an incoming server request and log its details
27     *
28     * @param ServerRequestInterface $request The request to process
29     * @param RequestHandlerInterface $handler The handler to process the request
30     * @return ResponseInterface The resulting response
31     * @throws \Throwable If an error occurs during request handling
32     */
33    #[\Override]
34    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
35    {
36        try {
37            $response = $handler->handle($request);
38            $this->logger->logRequest($request, $response);
39            return $response;
40        } catch (\Throwable $e) {
41            $this->logger->logError($e, $request);
42            throw $e;
43        }
44    }
45}