CallbackHandler::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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