Completed
Push — master ( ed3a3e...3e13b9 )
by Vladimir
02:37
created

ChannelServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A boot() 0 13 1
A channels() 0 4 1
A registerManager() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation\Providers;
6
7
use FondBot\Framework\Application;
8
use FondBot\Channels\ChannelManager;
9
use FondBot\Contracts\Channels\Manager;
10
use Illuminate\Support\ServiceProvider;
11
12
/**
13
 * @property Application $app
14
 */
15
class ChannelServiceProvider extends ServiceProvider
16
{
17
    /**
18
     * Register application services.
19
     */
20 83
    public function register(): void
21
    {
22 83
        $this->registerManager();
23 83
    }
24
25
    /**
26
     * Boot application services.
27
     */
28 83
    public function boot(): void
29
    {
30
        /** @var ChannelManager $manager */
31 83
        $manager = $this->app[Manager::class];
32
33 83
        $manager->register(
34 83
            collect($this->channels())
35 83
                ->mapWithKeys(function (array $parameters, string $name) {
36
                    return [$name => $parameters];
37 83
                })
38 83
                ->toArray()
39
        );
40 83
    }
41
42
    /**
43
     * Define bot channels.
44
     *
45
     * @return array
46
     */
47 83
    protected function channels(): array
48
    {
49 83
        return [];
50
    }
51
52
    private function registerManager(): void
53
    {
54 83
        $this->app->singleton(Manager::class, function () {
55 83
            return new ChannelManager($this->app);
56 83
        });
57
58
        $this->app->alias(Manager::class, ChannelManager::class);
59
    }
60
}
61