Completed
Push — master ( fc63d4...58d04b )
by Yohan
06:35 queued 04:20
created

Callback::call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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