Completed
Push — master ( f73df0...286c6f )
by Markus
23s queued 12s
created

QueueSQSServiceProvider::createClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 7
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Jellyfish\QueueSQS;
4
5
use Aws\Sqs\SqsClient;
6
use Pimple\Container;
7
use Pimple\ServiceProviderInterface;
8
9
class QueueSQSServiceProvider implements ServiceProviderInterface
10
{
11
    /**
12
     * @param \Pimple\Container $pimple
13
     *
14
     * @return void
15
     */
16
    public function register(Container $pimple): void
17
    {
18
        $this->registerQueueClient($pimple);
19
    }
20
21
    /**
22
     * @param \Pimple\Container $container
23
     *
24
     * @return \Jellyfish\QueueSQS\QueueSQSServiceProvider
25
     */
26
    protected function registerQueueClient(Container $container): QueueSQSServiceProvider
27
    {
28
        $self = $this;
29
30
        $container->offsetSet('queue_client', function (Container $container) use ($self) {
31
            return new QueueClient(
32
                $self->createSqsClient($container),
33
                $container->offsetGet('message_mapper')
34
            );
35
        });
36
37
        return $this;
38
    }
39
40
    /**
41
     * @param \Pimple\Container $container
42
     *
43
     * @return \Aws\Sqs\SqsClient
44
     */
45
    protected function createSqsClient(Container $container): SqsClient
46
    {
47
        $config = $container->offsetGet('config');
48
49
        $sqsConfig = [
50
            'region' => $config->get(QueueSQSConstants::SQS_REGION, QueueSQSConstants::DEFAULT_SQS_REGION),
51
            'profile' => $config->get(QueueSQSConstants::SQS_PROFILE, QueueSQSConstants::DEFAULT_SQS_PROFILE),
52
            'version' => $config->get(QueueSQSConstants::SQS_VERSION, QueueSQSConstants::DEFAULT_SQS_VERSION),
53
        ];
54
55
        return new SqsClient($sqsConfig);
56
    }
57
}
58