Completed
Push — master ( 9318bf...655fa2 )
by Edgar
02:03
created

CallbackInvoker::callOnError()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 6
1
<?php
2
namespace nstdio\notymo;
3
4
use Closure;
5
use nstdio\notymo\exception\PushNotificationException;
6
7
/**
8
 * Class CallbackInvoker
9
 *
10
 * @package nstdio\notymo
11
 * @author  Edgar Asatryan <[email protected]>
12
 */
13
class CallbackInvoker implements LifeCycleCallback, LifeCycleCallbackInvoker
14
{
15
    /**
16
     * @var Closure
17
     */
18
    protected $onComplete;
19
20
    /**
21
     * @var Closure
22
     */
23
    protected $onEachSent;
24
25
    /**
26
     * @var Closure
27
     */
28
    protected $onError;
29
30
    /**
31
     * @inheritdoc
32
     */
33 7
    public function callOnComplete(MessageQueue $param)
34
    {
35 7
        if (isset($this->onComplete)) {
36 3
            call_user_func_array($this->onComplete, array($param));
37 3
        }
38 7
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43 6
    public function callOnEachSent(MessageInterface $message, $feedBack = null)
44
    {
45 6
        if (isset($this->onEachSent)) {
46 3
            call_user_func_array($this->onEachSent, array($message, $feedBack));
47 3
        }
48 6
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function callOnError(MessageInterface $message, PushNotificationException $exc)
54
    {
55
        if (isset($this->onError)) {
56
            call_user_func_array($this->onError, array($message, $exc));
57
        } else {
58
            throw $exc;
59
        }
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65 3
    public function onComplete(\Closure $callback)
66
    {
67 3
        $this->onComplete = $callback;
68 3
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73 5
    public function onEachSent(\Closure $callback)
74
    {
75 5
        $this->onEachSent = $callback;
76 5
    }
77
78
    /**
79
     * @inheritdoc
80
     */
81
    public function onError(Closure $callback)
82
    {
83
        $this->onError = $callback;
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89 3
    public function detach()
90
    {
91 3
        unset($this->onComplete, $this->onEachSent, $this->onError);
92
    }
93
}