Middleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 2
eloc 5
dl 0
loc 26
rs 10
c 0
b 0
f 0
ccs 4
cts 5
cp 0.8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A process() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Http;
5
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Server\MiddlewareInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
use Shoot\Shoot\PipelineInterface;
11
12
final class Middleware implements MiddlewareInterface
13
{
14
    /** @var PipelineInterface */
15
    private $pipeline;
16
17
    /**
18
     * @param PipelineInterface $pipeline
19
     */
20 1
    public function __construct(PipelineInterface $pipeline)
21
    {
22 1
        $this->pipeline = $pipeline;
23 1
    }
24
25
    /**
26
     * Process an incoming server request and return a response, optionally delegating
27
     * response creation to a handler.
28
     *
29
     * @param ServerRequestInterface  $request
30
     * @param RequestHandlerInterface $handler
31
     *
32
     * @return ResponseInterface
33
     */
34
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
35
    {
36 1
        return $this->pipeline->withContext($request, function () use ($request, $handler): ResponseInterface {
37
            return $handler->handle($request);
38 1
        });
39
    }
40
}
41