ChromeLoggerMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 6 1
1
<?php
2
3
namespace Kodus\Logging;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use Psr\Http\Server\MiddlewareInterface;
8
use Psr\Http\Server\RequestHandlerInterface;
9
10
/**
11
 * Add this to the *top* of your middleware stack - it will delegate to the rest of the
12
 * middleware stack unconditionally, then decorates the Response with ChromeLogger headers.
13
 */
14
class ChromeLoggerMiddleware implements MiddlewareInterface
15
{
16
    /**
17
     * @var ChromeLogger
18
     */
19
    private $logger;
20
21
    /**
22
     * @param ChromeLogger $logger
23
     */
24
    public function __construct(ChromeLogger $logger)
25
    {
26
        $this->logger = $logger;
27
    }
28
29
    /**
30
     * Process an incoming server request and return a response, optionally delegating
31
     * response creation to a handler.
32
     *
33
     * @param ServerRequestInterface  $request
34
     * @param RequestHandlerInterface $handler
35
     *
36
     * @return ResponseInterface
37
     */
38
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
39
    {
40
        $response = $handler->handle($request);
41
42
        return $this->logger->writeToResponse($response);
43
    }
44
}
45