Completed
Pull Request — master (#124)
by
unknown
04:50 queued 01:06
created

Callback   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 2 Features 4
Metric Value
wmc 7
c 7
b 2
f 4
cbo 3
dl 0
loc 71
ccs 13
cts 13
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSpecification() 0 4 1
A getCallbacks() 0 4 1
A getClauses() 0 4 1
A __invoke() 0 6 2
A call() 0 4 1
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
    const CLAUSE_AFTER = 'after';
13
    const CLAUSE_BEFORE = 'before';
14
    const CLAUSE_FROM = 'from';
15
    const CLAUSE_TO = 'to';
16
    const CLAUSE_ON = 'on';
17
    const CLAUSE_DO = 'do';
18
19
    /**
20
     * @var CallbackSpecificationInterface
21
     */
22
    private $specification;
23
24
    /**
25
     * @var array callable
26 55
     */
27
    private $callable;
28 55
29 55
    /**
30 55
     * @param CallbackSpecificationInterface $callbackSpecification
31
     * @param $callable
32
     */
33
    public function __construct(CallbackSpecificationInterface $callbackSpecification, $callable)
34
    {
35 5
        $this->specification = $callbackSpecification;
36
        $this->callable = $callable;
37 5
    }
38
39
    /**
40
     * @return CallbackSpecificationInterface
41
     */
42
    public function getSpecification()
43 35
    {
44
        return $this->specification;
45 35
    }
46 30
47 24
    /**
48 35
     * @return array callable
49
     */
50
    public function getCallbacks()
51
    {
52
        return $this->callable;
53 30
    }
54
55 30
    /**
56
     * @return array
57
     */
58
    public function getClauses()
59
    {
60
        return $this->specification->getClauses();
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function __invoke(TransitionEvent $event)
67
    {
68
        if ($this->specification->isSatisfiedBy($event)) {
69
            $this->call($event->getStateMachine()->getObject(), $event);
70
        }
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    protected function call($object, TransitionEvent $event)
77
    {
78
        return call_user_func($this->callable, $object, $event);
79
    }
80
}
81