SqsFifoConnector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
c 2
b 0
f 0
dl 0
loc 37
ccs 20
cts 20
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A connect() 0 28 4
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(
40 115
                Arr::except($config, ['token'])
41 115
            ),
42 115
            $config['queue'],
43 115
            $config['prefix'] ?? '',
44 115
            $config['suffix'] ?? '',
45 115
            (bool)($config['after_commit'] ?? null),
46 115
            $group,
47 115
            $deduplicator,
48 115
            $allowDelay
49 115
        );
50
    }
51
}
52