Completed
Push — master ( afce1d...f8221d )
by Vladimir
09:37
created

ConversationServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 2
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\Providers;
6
7
use FondBot\Foundation\Kernel;
8
use Illuminate\Contracts\Cache\Store;
9
use FondBot\Conversation\IntentManager;
10
use Illuminate\Support\ServiceProvider;
11
use FondBot\Conversation\FallbackIntent;
12
use FondBot\Conversation\SessionManager;
13
use FondBot\Conversation\ConversationManager;
14
use Illuminate\Contracts\Config\Repository as Config;
15
16
class ConversationServiceProvider extends ServiceProvider
17
{
18
    /**
19
     * Register the service provider.
20
     *
21
     * @return void
22
     */
23
    public function register(): void
24
    {
25
        $this->app->singleton(ConversationManager::class, function () {
26
            return new ConversationManager($this->app->make(Kernel::class));
0 ignored issues
show
Unused Code introduced by
The call to ConversationManager::__construct() has too many arguments starting with $this->app->make(\FondBo...undation\Kernel::class).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
27
        });
28
29
        $this->app->singleton(SessionManager::class, function () {
30
            return new SessionManager(
31
                $this->app,
32
                $this->app->make(Store::class)
33
            );
34
        });
35
36
        $this->app->singleton(IntentManager::class, function () {
37
            /** @var Config $config */
38
            $config = $this->app[Config::class];
39
40
            $intents = $config->get('fondbot.intents', []);
41
            $fallbackIntent = $config->get('fondbot.fallback_intent', FallbackIntent::class);
42
43
            $manager = new IntentManager;
44
            $manager->register($intents, $fallbackIntent);
45
46
            return $manager;
47
        });
48
    }
49
50
    /**
51
     * Get the services provided by the provider.
52
     *
53
     * @return array
54
     */
55
    public function provides(): array
56
    {
57
        return [
58
            ConversationManager::class,
59
            SessionManager::class,
60
            IntentManager::class,
61
        ];
62
    }
63
}
64