Passed
Push — master ( d359a0...4c7365 )
by Vladimir
02:29
created

ChannelServiceProvider::config()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 3
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Channels;
6
7
use Illuminate\Support\ServiceProvider;
8
use Illuminate\Contracts\Config\Repository;
9
10
class ChannelServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Register the service provider.
14
     *
15
     * @return void
16
     */
17
    public function register(): void
18
    {
19
        $this->app->singleton(ChannelManager::class, function () {
20
            /** @var array $channels */
21
            $channels = collect($this->config())
22
                ->mapWithKeys(function (array $parameters, string $name) {
23
                    return [$name => $parameters];
24
                })
25
                ->toArray();
26
27
            $manager = new ChannelManager;
28
            $manager->register($channels);
29
30
            return $manager;
31
        });
32
    }
33
34
    private function config(): array
35
    {
36
        /** @var Repository $config */
37
        $config = $this->app[Repository::class];
38
39
        return $config->get('fondbot.channels');
40
    }
41
}
42