RequestHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 13 2
1
<?php
2
/**
3
 * This file is part of the http-middleware package.
4
 *
5
 * Copyright (c) Dusan Vejin
6
 *
7
 * For full copyright and license information, please refer to the LICENSE file,
8
 * located at the package root folder.
9
 */
10
11
declare(strict_types=1);
12
13
namespace WeCodeIn\Http\Server;
14
15
use Psr\Http\Message\ResponseFactoryInterface;
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
21
class RequestHandler implements RequestHandlerInterface
22
{
23
    protected $responseFactory;
24
    protected $middlewares;
25
26 5
    public function __construct(ResponseFactoryInterface $responseFactory, MiddlewareInterface ...$middlewares)
27
    {
28 5
        $this->responseFactory = $responseFactory;
29 5
        $this->middlewares = $middlewares;
30 5
    }
31
32 4
    public function handle(ServerRequestInterface $request): ResponseInterface
33
    {
34 4
        $handler = clone $this;
35
36 4
        if (null === key($handler->middlewares)) {
37 2
            return $this->responseFactory->createResponse();
38
        }
39
40 3
        $middleware = current($handler->middlewares);
41 3
        next($handler->middlewares);
42
43 3
        return $middleware->process($request, $handler);
44
    }
45
}
46