Completed
Push — master ( b112db...b25060 )
by Vladimir
10:13
created

ChannelServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 21.43%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 3
cts 14
cp 0.2143
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A config() 0 7 1
A register() 0 16 1
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 83
        $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($this->app);
0 ignored issues
show
Compatibility introduced by
$this->app of type object<Illuminate\Contra...Foundation\Application> is not a sub-type of object<Illuminate\Foundation\Application>. It seems like you assume a concrete implementation of the interface Illuminate\Contracts\Foundation\Application to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
28
            $manager->register($channels);
29
30
            return $manager;
31 83
        });
32 83
    }
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