QueueableRequestHandler::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Http\Router\RequestHandler;
15
16
use Psr\Http\Message\ResponseInterface;
17
use Psr\Http\Message\ServerRequestInterface;
18
use Psr\Http\Server\MiddlewareInterface;
19
use Psr\Http\Server\RequestHandlerInterface;
20
use SplQueue;
21
22
/**
23
 * @since 2.0.0
24
 *
25
 * @extends SplQueue<MiddlewareInterface>
26
 */
27
final class QueueableRequestHandler extends SplQueue implements RequestHandlerInterface
28
{
29 5
    public function __construct(
30
        private readonly RequestHandlerInterface $endpoint,
31
    ) {
32 5
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37 5
    public function handle(ServerRequestInterface $request): ResponseInterface
38
    {
39 5
        return $this->isEmpty()
40 4
            ? $this->endpoint->handle($request)
41 5
            : ($clone = clone $this)->dequeue()->process($request, $clone);
42
    }
43
}
44