Passed
Pull Request — master (#34)
by Anatoly
02:04
created

CallableRequestHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 4
c 1
b 0
f 0
dl 0
loc 26
rs 10
ccs 5
cts 5
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 3 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router\RequestHandler;
13
14
/**
15
 * Import classes
16
 */
17
use Psr\Http\Message\ResponseInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
use Psr\Http\Server\RequestHandlerInterface;
20
21
/**
22
 * CallableRequestHandler
23
 */
24
class CallableRequestHandler implements RequestHandlerInterface
25
{
26
27
    /**
28
     * The request handler callback
29
     *
30
     * @var callable
31
     */
32
    private $callback;
33
34
    /**
35
     * Constructor of the class
36
     *
37
     * @param callable $callback
38
     */
39 2
    public function __construct(callable $callback)
40
    {
41 2
        $this->callback = $callback;
42 2
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47 1
    public function handle(ServerRequestInterface $request) : ResponseInterface
48
    {
49 1
        return ($this->callback)($request);
50
    }
51
}
52