Completed
Push — master ( 16b7cb...b112db )
by Vladimir
07:44
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\Support\ServiceProvider;
8
use Illuminate\Contracts\Cache\Repository as Cache;
9
10
class ConversationServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Register the service provider.
14
     *
15
     * @return void
16
     */
17
    public function register(): void
18
    {
19
        $this->registerSessionManager();
20
        $this->registerIntentManager();
21
    }
22
23
    private function registerSessionManager(): void
24
    {
25
        $this->app->singleton(SessionManager::class, function () {
26
            return new SessionManager($this->app, resolve(Cache::class));
27
        });
28
    }
29
30
    private function registerIntentManager(): void
31
    {
32
        $this->app->singleton(IntentManager::class, function () {
33
            $intents = config('fondbot.conversation.intents');
34
            $fallbackIntent = config('fondbot.conversation.fallback_intent', FallbackIntent::class);
35
36
            $manager = new IntentManager;
37
            $manager->register($intents, $fallbackIntent);
38
39
            return $manager;
40
        });
41
    }
42
}
43