CallbackHandler::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Whoops - php errors for cool kids
4
 * @author Filipe Dobreira <http://github.com/filp>
5
 */
6
7
namespace Whoops\Handler;
8
9
use InvalidArgumentException;
10
11
/**
12
 * Wrapper for Closures passed as handlers. Can be used
13
 * directly, or will be instantiated automagically by Whoops\Run
14
 * if passed to Run::pushHandler
15
 */
16
class CallbackHandler extends Handler
17
{
18
    /**
19
     * @var callable
20
     */
21
    protected $callable;
22
23
    /**
24
     * @throws InvalidArgumentException If argument is not callable
25
     * @param  callable                 $callable
26
     */
27 1
    public function __construct($callable)
28
    {
29 1
        if (!is_callable($callable)) {
30
            throw new InvalidArgumentException(
31
                'Argument to ' . __METHOD__ . ' must be valid callable'
32
            );
33
        }
34
35 1
        $this->callable = $callable;
36 1
    }
37
38
    /**
39
     * @return int|null
40
     */
41 1
    public function handle()
42
    {
43 1
        $exception = $this->getException();
44 1
        $inspector = $this->getInspector();
45 1
        $run       = $this->getRun();
46 1
        $callable  = $this->callable;
47
48
        // invoke the callable directly, to get simpler stacktraces (in comparison to call_user_func).
49
        // this assumes that $callable is a properly typed php-callable, which we check in __construct().
50 1
        return $callable($exception, $inspector, $run);
51
    }
52
}
53