SnsServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace NotificationChannels\AwsSns;
4
5
use Aws\Sns\SnsClient as SnsService;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\ServiceProvider;
8
9
class SnsServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     */
14 2
    public function boot()
15
    {
16 2
        $this->app->when(SnsChannel::class)
17 2
            ->needs(Sns::class)
18
            ->give(function () {
19 2
                return new Sns($this->app->make(SnsService::class));
20 2
            });
21
22
        $this->app->bind(SnsService::class, function () {
23 2
            $config = array_merge(['version' => 'latest'], $this->app['config']['services.sns']);
24
25 2
            return new SnsService($this->addSnsCredentials($config));
26 2
        });
27 2
    }
28
29 2
    protected function addSnsCredentials($config): array
30
    {
31 2
        if (! empty($config['key']) && ! empty($config['secret'])) {
32 2
            $config['credentials'] = Arr::only($config, ['key', 'secret', 'token']);
33
        }
34
35 2
        return $config;
36
    }
37
}
38