Completed
Push — master ( 6be938...3b6271 )
by Edgar
02:01
created

CallbackInvoker   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 0
dl 0
loc 56
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A callOnComplete() 0 6 2
A callOnEachSent() 0 6 2
A onComplete() 0 4 1
A onEachSent() 0 4 1
A detach() 0 4 1
1
<?php
2
namespace nstdio\notymo;
3
4
/**
5
 * Class CallbackInvoker
6
 *
7
 * @package nstdio\notymo
8
 * @author  Edgar Asatryan <[email protected]>
9
 */
10
class CallbackInvoker implements LifeCycleCallback, LifeCycleCallbackInvoker
11
{
12
    /**
13
     * @var callable
14
     */
15
    protected $onComplete;
16
17
    /**
18
     * @var callable
19
     */
20
    protected $onEachSent;
21
22
    /**
23
     * @var callable
24
     */
25
    protected $onError;
26
27 7
    public function callOnComplete(MessageQueue $param)
28
    {
29 7
        if (isset($this->onComplete)) {
30 3
            call_user_func_array($this->onComplete, array($param));
31 3
        }
32 7
    }
33
34 6
    public function callOnEachSent(MessageInterface $message, $feedBack = null)
35
    {
36 6
        if (isset($this->onEachSent)) {
37 3
            call_user_func_array($this->onEachSent, array($message, $feedBack));
38 3
        }
39 6
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44 3
    public function onComplete(callable $callback)
45
    {
46 3
        $this->onComplete = $callback;
47 3
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52 5
    public function onEachSent(callable $callback)
53
    {
54 5
        $this->onEachSent = $callback;
55 5
    }
56
57
    /**
58
     * Removes all callbacks.
59
     * Will be called immediately after `onSent`.
60
     */
61 3
    public function detach()
62
    {
63 3
        unset($this->onComplete, $this->onEachSent, $this->onError);
64
    }
65
}