CallableHandler::__construct()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of coisa/http.
5
 *
6
 * (c) Felipe Sayão Lobato Abreu <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
declare(strict_types=1);
13
14
namespace CoiSA\Http\Handler;
15
16
use Psr\Http\Message\ResponseInterface;
17
use Psr\Http\Message\ServerRequestInterface;
18
use Psr\Http\Server\RequestHandlerInterface;
19
20
/**
21
 * Class CallableHandler
22
 *
23
 * @package CoiSA\Http\Handler
24
 */
25
class CallableHandler implements RequestHandlerInterface
26
{
27
    /**
28
     * @var callable
29
     */
30
    private $callback;
31
32
    /**
33
     * CallableHandler constructor.
34
     *
35
     * @param callable $callback
36
     */
37 2
    public function __construct(callable $callback)
38
    {
39 2
        $this->callback = $callback;
40 2
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 2
    public function handle(ServerRequestInterface $request): ResponseInterface
46
    {
47 2
        return \call_user_func($this->callback, $request);
48
    }
49
}
50