Passed
Push — 1.0 ( 1757a3...241f9e )
by Vladimir
02:41
created

IntentServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 21 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Providers;
6
7
use FondBot\Application\Config;
8
use FondBot\Conversation\IntentManager;
9
use FondBot\Conversation\FallbackIntent;
10
use League\Container\ServiceProvider\AbstractServiceProvider;
11
12
class IntentServiceProvider extends AbstractServiceProvider
13
{
14
    protected $provides = [
15
        IntentManager::class,
16
    ];
17
18
    /**
19
     * Use the register method to register items with the container via the
20
     * protected $this->container property or the `getContainer` method
21
     * from the ContainerAwareTrait.
22
     *
23
     * @return void
24
     */
25
    public function register(): void
26
    {
27
        /** @var Config $config */
28
        $config = $this->getContainer()->get(Config::class);
29
30
        /** @var array $intents */
31
        $intents = $config->get('intents', []);
32
33
        /** @var string $fallbackIntent */
34
        $fallbackIntent = $config->get('fallback_intent', FallbackIntent::class);
35
36
        $manager = new IntentManager();
37
38
        foreach ($intents as $intent) {
39
            $manager->add($this->getContainer()->get($intent));
40
        }
41
42
        $manager->setFallbackIntent($this->getContainer()->get($fallbackIntent));
43
44
        $this->getContainer()->add(IntentManager::class, $manager);
45
    }
46
}
47