Completed
Push — master ( bf6746...03a380 )
by Antonio
02:19
created

SqsQueueStoreConnection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 80.95%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 47
ccs 17
cts 21
cp 0.8095
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A connect() 0 17 2
A getInstance() 0 8 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
            $this->instance = null; // close previous connection
26
        }
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
            $this->connect();
49
        }
50
51 1
        return $this->instance;
52
    }
53
}
54