Callback::checkCondition()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Metabor\Statemachine\Condition;
4
5
use ArrayAccess;
6
use InvalidArgumentException;
7
use Metabor\Named;
8
use MetaborStd\Statemachine\ConditionInterface;
9
10
/**
11
 * @author otischlinger
12
 */
13
class Callback extends Named implements ConditionInterface
14
{
15
    /**
16
     * @var callable
17
     */
18
    private $callable;
19
20
    /**
21
     * @param string   $name
22
     * @param callable $callable
23
     */
24 2
    public function __construct($name, $callable)
25
    {
26 2
        parent::__construct($name);
27 2
        if (!is_callable($callable)) {
28
            throw new InvalidArgumentException('Argument is not callable!');
29
        }
30 2
        $this->callable = $callable;
31 2
    }
32
33
    /**
34
     * @see MetaborStd\Statemachine.ConditionInterface::checkCondition()
35
     */
36 1
    public function checkCondition($subject, ArrayAccess $context)
37
    {
38 1
        return call_user_func($this->callable, $subject, $context);
39
    }
40
}
41