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

CallbackInvoker::onComplete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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
}