CallbackKernel   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A handleRequest() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PHPFastCGI\FastCGIDaemon;
6
7
use PHPFastCGI\FastCGIDaemon\Http\RequestInterface;
8
9
/**
10
 * Wraps a callback (such as a closure, function or class and method pair) as an
11
 * implementation of the kernel interface.
12
 */
13
final class CallbackKernel implements KernelInterface
14
{
15
    /**
16
     * @var callable
17
     */
18
    private $callback;
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param callable $handler The handler callback to wrap
24
     *
25
     * @throws \InvalidArgumentException When not given callable callback
26
     */
27
    public function __construct(callable $handler)
28
    {
29
        if (!is_callable($handler)) {
30
            throw new \InvalidArgumentException('Handler callback is not callable');
31
        }
32
33
        $this->callback = $handler;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function handleRequest(RequestInterface $request)
40
    {
41
        return call_user_func($this->callback, $request);
42
    }
43
}
44