Callback::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Finite\Event\Callback;
4
5
use Finite\Event\TransitionEvent;
6
7
/**
8
 * @author Yohan Giarelli <[email protected]>
9
 */
10
class Callback implements CallbackInterface
11
{
12
    /**
13
     * @var CallbackSpecificationInterface
14
     */
15
    private $specification;
16
17
    /**
18
     * @var callable
19
     */
20
    private $callable;
21
22
    /**
23
     * @param CallbackSpecificationInterface $callbackSpecification
24
     * @param callable                       $callable
25
     */
26 55
    public function __construct(CallbackSpecificationInterface $callbackSpecification, $callable)
27
    {
28 55
        $this->specification = $callbackSpecification;
29 55
        $this->callable = $callable;
30 55
    }
31
32
    /**
33
     * @return CallbackSpecificationInterface
34
     */
35 5
    public function getSpecification()
36
    {
37 5
        return $this->specification;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 35
    public function __invoke(TransitionEvent $event)
44
    {
45 35
        if ($this->specification->isSatisfiedBy($event)) {
46 30
            $this->call($event->getStateMachine()->getObject(), $event);
47 18
        }
48 35
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 30
    protected function call($object, TransitionEvent $event)
54
    {
55 30
        return call_user_func($this->callable, $object, $event);
56
    }
57
}
58