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

ConversationServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
A registerSessionManager() 0 9 1
A registerIntentManager() 0 12 1
A config() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation;
6
7
use Illuminate\Contracts\Cache\Store;
8
use Illuminate\Support\ServiceProvider;
9
use Illuminate\Contracts\Config\Repository;
10
11
class ConversationServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Register the service provider.
15
     *
16
     * @return void
17
     */
18
    public function register(): void
19
    {
20
        $this->registerSessionManager();
21
        $this->registerIntentManager();
22
    }
23
24
    private function registerSessionManager(): void
25
    {
26
        $this->app->singleton(SessionManager::class, function () {
27
            return new SessionManager(
28
                $this->app,
29
                $this->app->make(Store::class)
30
            );
31
        });
32
    }
33
34
    private function registerIntentManager(): void
35
    {
36
        $this->app->singleton(IntentManager::class, function () {
37
            $intents = array_get($this->config(), 'intents', []);
38
            $fallbackIntent = array_get($this->config(), 'fallback_intent', FallbackIntent::class);
39
40
            $manager = new IntentManager;
41
            $manager->register($intents, $fallbackIntent);
42
43
            return $manager;
44
        });
45
    }
46
47
    private function config(): array
48
    {
49
        /** @var Repository $config */
50
        $config = $this->app[Repository::class];
51
52
        return $config->get('fondbot.conversation');
53
    }
54
}
55