CallbackInvoker::callOnComplete()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
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 2
    public function callOnError(MessageInterface $message, PushNotificationException $exc)
54
    {
55 2
        if (isset($this->onError)) {
56 1
            call_user_func_array($this->onError, array($message, $exc));
57 1
        } else {
58 1
            throw $exc;
59
        }
60 1
    }
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 1
    public function onError(Closure $callback)
82
    {
83 1
        $this->onError = $callback;
84 1
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89 3
    public function detach()
90
    {
91 3
        unset($this->onComplete, $this->onEachSent, $this->onError);
92
    }
93
}