Passed
Branch ci-test (67883f)
by Patrick
13:41
created

SqsFifoConnector   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 92%

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 23
cts 25
cp 0.92
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A connect() 0 21 4
A getDefaultConfiguration() 0 14 2
1
<?php
2
3
namespace ShiftOneLabs\LaravelSqsFifoQueue\Queue\Connectors;
4
5
use Aws\Sqs\SqsClient;
6
use InvalidArgumentException;
7
use Illuminate\Queue\Connectors\SqsConnector;
8
use ShiftOneLabs\LaravelSqsFifoQueue\SqsFifoQueue;
9
10
class SqsFifoConnector extends SqsConnector
11
{
12
    /**
13
     * Establish a queue connection.
14
     *
15
     * @param  array  $config
16
     *
17
     * @return \Illuminate\Contracts\Queue\Queue
18
     */
19 152
    public function connect(array $config)
20
    {
21 152
        $config = $this->getDefaultConfiguration($config);
22
23 152
        if (!ends_with($config['queue'], '.fifo')) {
24 38
            throw new InvalidArgumentException('FIFO queue name must end in ".fifo"');
25
        }
26
27 114
        if ($config['key'] && $config['secret']) {
28
            $config['credentials'] = array_only($config, ['key', 'secret']);
29
        }
30
31 114
        $group = array_pull($config, 'group', 'default');
32 114
        $deduplicator = array_pull($config, 'deduplicator', 'unique');
33
34 114
        return new SqsFifoQueue(
35 114
            new SqsClient($config),
36 114
            $config['queue'],
37 114
            array_get($config, 'prefix', ''),
38 114
            $group,
39 78
            $deduplicator
40 36
        );
41
    }
42
43
    /**
44
     * Get the default configuration for SQS.
45
     *
46
     * @param  array  $config
47
     *
48
     * @return array
49
     */
50 152
    protected function getDefaultConfiguration(array $config)
51
    {
52
        // Laravel >= 5.1 has the "getDefaultConfiguration" method.
53 152
        if (method_exists(get_parent_class(), 'getDefaultConfiguration')) {
54 92
            return parent::getDefaultConfiguration($config);
55
        }
56
57 60
        return array_merge([
58 60
            'version' => 'latest',
59
            'http' => [
60 24
                'timeout' => 60,
61 24
                'connect_timeout' => 60,
62 24
            ],
63 60
        ], $config);
64
    }
65
}
66