Completed
Push — master ( 3fcd76...5b4ebb )
by Andrew
01:57
created

CallbackKernel   A

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