CallbackHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Simply\Application\Handler;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use Psr\Http\Server\RequestHandlerInterface;
8
9
/**
10
 * A handler that calls the given callback to generate the response.
11
 * @author Riikka Kalliomäki <[email protected]>
12
 * @copyright Copyright (c) 2018 Riikka Kalliomäki
13
 * @license http://opensource.org/licenses/mit-license.php MIT License
14
 */
15
class CallbackHandler implements RequestHandlerInterface
16
{
17
    /** @var callable The callback to call with the request */
18
    private $callback;
19
20
    /**
21
     * CallbackHandler constructor.
22
     * @param callable $callback The callback to call with the request
23
     */
24 12
    public function __construct(callable $callback)
25
    {
26 12
        $this->callback = $callback;
27 12
    }
28
29
    /** {@inheritdoc} */
30 12
    public function handle(ServerRequestInterface $request): ResponseInterface
31
    {
32 12
        return ($this->callback)($request);
33
    }
34
}
35