PassThroughRequestHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\React;
6
7
use Generator;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
12
use function React\Promise\resolve;
13
14
/**
15
 * @internal
16
 */
17
final class PassThroughRequestHandler implements RequestHandlerInterface
18
{
19
    /**
20
     * @var callable
21
     */
22
    private $next;
23
24
    /**
25
     * @param callable $next
26
     */
27
    public function __construct(callable $next)
28
    {
29
        $this->next = $next;
30
    }
31
32
    public function handle(ServerRequestInterface $request): ResponseInterface
33
    {
34
        return new PromiseResponse(resolve($this->next)
35
            ->then(static fn($next) => $next($request)->current()));
36
    }
37
}
38