Passed
Push — master ( b25060...4672bf )
by Vladimir
02:19
created

ConversationServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 53.85%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 7
cts 13
cp 0.5385
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
A registerSessionManager() 0 6 1
A registerIntentManager() 0 11 1
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 83
    public function register(): void
18
    {
19 83
        $this->registerSessionManager();
20 83
        $this->registerIntentManager();
21 83
    }
22
23
    private function registerSessionManager(): void
24
    {
25 83
        $this->app->singleton(SessionManager::class, function () {
26
            return new SessionManager($this->app, resolve(Cache::class));
27 83
        });
28 83
    }
29
30
    private function registerIntentManager(): void
31
    {
32
        $this->app->singleton(IntentManager::class, function () {
33
            return tap(new IntentManager, function (IntentManager $manager) {
34
                $intents = config('fondbot.conversation.intents');
35
                $fallbackIntent = config('fondbot.conversation.fallback_intent', FallbackIntent::class);
36
37
                $manager->register($intents, $fallbackIntent);
38
            });
39
        });
40
    }
41
}
42