RequestHandler::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 2
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of slick/http
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Slick\Http\Server;
13
14
use Psr\Http\Message\ResponseInterface;
15
use Psr\Http\Message\ServerRequestInterface;
16
use Psr\Http\Server\RequestHandlerInterface;
17
18
/**
19
 * RequestHandler
20
 *
21
 * @package Slick\Http\Server
22
*/
23
class RequestHandler implements RequestHandlerInterface
24
{
25
    /**
26
     * @var callable
27
     */
28
    private $callback;
29
30
    /**
31
     * Creates a Request Handler
32
     *
33
     * @param callable $callback
34
     */
35
    public function __construct(callable $callback)
36
    {
37
        $this->callback = $callback;
38
    }
39
40
    /**
41
     * Handle the request and return a response.
42
     *
43
     * @param ServerRequestInterface $request
44
     *
45
     * @return ResponseInterface
46
     */
47
    public function handle(ServerRequestInterface $request): ResponseInterface
48
    {
49
        $response = \call_user_func($this->callback, $request);
50
        return $response;
51
    }
52
}
53