Completed
Push — refactor-callback-handler ( 07f6ac...7e93ef )
by Yohan
03:33
created

Callback   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSpecification() 0 4 1
A call() 0 4 1
A __invoke() 0 6 2
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 60
    public function __construct(CallbackSpecificationInterface $callbackSpecification, $callable)
29
    {
30 60
        $this->specification = $callbackSpecification;
31 60
        $this->callable      = $callable;
32 60
    }
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 call($object, TransitionEvent $event)
46
    {
47 35
        return call_user_func($this->callable, $object, $event);
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53 35
    public function __invoke(TransitionEvent $event)
54
    {
55 35
        if ($this->specification->isSatisfiedBy($event)) {
56 30
            $this->call($event->getStateMachine()->getObject(), $event);
57 24
        }
58 35
    }
59
}
60