HeaderMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 4 1
1
<?php
2
3
namespace example\components;
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
class HeaderMiddleware implements MiddlewareInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private $header;
16
17
    /**
18
     * @var string
19
     */
20
    private $value;
21
22
    /**
23
     * HeaderMiddleware constructor.
24
     * @param string $header
25
     * @param string $value
26
     */
27
    public function __construct(string $header, string $value)
28
    {
29
        $this->header = $header;
30
        $this->value = $value;
31
    }
32
33
    /**
34
     * @param ServerRequestInterface $request
35
     * @param RequestHandlerInterface $handler
36
     * @return ResponseInterface
37
     */
38
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
39
    {
40
        $response = $handler->handle($request);
41
        return $response->withHeader($this->header, $this->value);
42
    }
43
}
44