Completed
Push — master ( 964908...9eae13 )
by Antonio
02:35
created

SqsQueueStoreConnection::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
namespace Da\Mailer\Queue\Backend\Sqs;
3
4
use Da\Mailer\Queue\Backend\AbstractQueueStoreConnection;
5
use Aws\Sqs\SqsClient;
6
7
class SqsQueueStoreConnection extends AbstractQueueStoreConnection
8
{
9
    /**
10
     * SqsQueueStoreConnection constructor.
11
     *
12
     * @param array $configuration
13
     */
14 2
    public function __construct(array $configuration = [])
15
    {
16 2
        parent::__construct($configuration);
17 2
    }
18
19
    /**
20
     * @inheritdoc
21
     */
22 1
    public function connect()
23
    {
24 1
        if ($this->instance !== null) {
25 1
            $this->instance = null; // close previous connection
26 1
        }
27 1
        $key = $this->getConfigurationValue('key');
28 1
        $secret = $this->getConfigurationValue('secret');
29 1
        $region = $this->getConfigurationValue('region');
30
31 1
        $this->instance = SqsClient::factory([
32 1
            'key' => $key,
33 1
            'secret' => $secret,
34 1
            'region' => $region,
35 1
        ]);
36
37 1
        return $this;
38
    }
39
40
    /**
41
     * Returns the connection instance.
42
     *
43
     * @return SqsClient|null
44
     */
45 1
    public function getInstance()
46
    {
47 1
        if ($this->instance === null) {
48 1
            $this->connect();
49 1
        }
50
51 1
        return $this->instance;
52
    }
53
}
54