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

IntentServiceProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 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