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

ConversationServiceProvider::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\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