Passed
Push — master ( 6d8724...5349b1 )
by Patrick
04:01 queued 01:08
created

SqsFifoConnector::getDefaultConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 2
rs 10
1
<?php
2
3
namespace ShiftOneLabs\LaravelSqsFifoQueue\Queue\Connectors;
4
5
use Aws\Sqs\SqsClient;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Str;
8
use InvalidArgumentException;
9
use Illuminate\Queue\Connectors\SqsConnector;
10
use ShiftOneLabs\LaravelSqsFifoQueue\SqsFifoQueue;
11
12
class SqsFifoConnector extends SqsConnector
13
{
14
    /**
15
     * Establish a queue connection.
16
     *
17
     * @param  array  $config
18
     *
19
     * @return \Illuminate\Contracts\Queue\Queue
20
     */
21 120
    public function connect(array $config)
22
    {
23 120
        $config = $this->getDefaultConfiguration($config);
24
25 120
        if (!Str::endsWith($config['queue'], '.fifo')) {
26 5
            throw new InvalidArgumentException('FIFO queue name must end in ".fifo"');
27
        }
28
29 115
        if (!empty($config['key']) && !empty($config['secret'])) {
30 100
            $config['credentials'] = Arr::only($config, ['key', 'secret', 'token']);
31
        }
32
33
        // Pull the custom config options out of the config array sent to SqsClient.
34 115
        $group = Arr::pull($config, 'group', 'default');
35 115
        $deduplicator = Arr::pull($config, 'deduplicator', 'unique');
36 115
        $allowDelay = (bool)Arr::pull($config, 'allow_delay', false);
37
38 115
        return new SqsFifoQueue(
39 115
            new SqsClient($config),
40 115
            $config['queue'],
41 115
            $config['prefix'] ?? '',
42 115
            $config['suffix'] ?? '',
43 115
            (bool)($config['after_commit'] ?? null),
44 115
            $group,
45 115
            $deduplicator,
46 115
            $allowDelay
47 115
        );
48
    }
49
}
50