Completed
Branch master (755019)
by Oliver
12:48 queued 05:47
created

Callback::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4286
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
1
<?php
2
3
namespace Metabor\Callback;
4
5
use InvalidArgumentException;
6
use MetaborStd\CallbackInterface;
7
8
/**
9
 * @author Oliver Tischlinger
10
 */
11
class Callback implements CallbackInterface
12
{
13
    /**
14
     * @var callable
15
     */
16
    private $callable;
17
18
    /**
19
     * @param callable $callable
20
     */
21 7
    public function __construct($callable)
22
    {
23
        if (!is_callable($callable)) {
24
            throw new InvalidArgumentException('Argument is not callable!');
25
        }
26 7
        $this->callable = $callable;
27 7
    }
28
29
    /**
30
     * @see MetaborStd.CallbackInterface::__invoke()
31
     */
32 4
    public function __invoke()
33
    {
34 4
        $args = func_get_args();
35
36
        return call_user_func_array($this->callable, $args);
37
    }
38
}
39