Completed
Push — master ( 24c6fe...cc1b0b )
by Edgar
02:01
created

AbstractNotification::setStreamWrapper()   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 AbstractNotification
6
 *
7
 * @package nstdio\notymo
8
 * @author  Edgar Asatryan <[email protected]>
9
 */
10
abstract class AbstractNotification implements PushNotificationInterface
11
{
12
    /**
13
     * @var MessageQueue
14
     */
15
    protected $messageQueue;
16
17
    /**
18
     * @var Connection
19
     */
20
    protected $stream;
21
22 2
    public function __construct()
23
    {
24 2
        $this->messageQueue = new MessageQueue();
25 2
    }
26
27
    abstract public function send();
28
29 1
    public function enqueue(MessageInterface $message)
30
    {
31 1
        $this->messageQueue->enqueue($message);
32 1
    }
33
34
    /**
35
     * @param Connection $wrapper
36
     */
37 1
    public function setStreamWrapper(Connection $wrapper)
38
    {
39 1
        $this->stream = $wrapper;
40 1
    }
41
42
    abstract protected function createPayload(MessageInterface $message);
43
44 1
    final protected function openConnection()
45
    {
46 1
        $this->lazyInitStream();
47
48 1
        $this->stream->open($this->getConnectionParams(), null);
49
50 1
        return $this;
51
    }
52
53 1
    private function lazyInitStream()
54
    {
55 1
        if ($this->stream === null) {
56
            $this->stream = new CurlWrapper();
57
        }
58 1
    }
59
60
    /**
61
     * @return array
62
     */
63
    abstract protected function getConnectionParams();
64
}