Middleware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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