Passed
Push — 1.0 ( 12d132...dd1957 )
by Vladimir
06:10
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\Conversation\IntentManager;
8
use FondBot\Conversation\FallbackIntent;
9
use League\Container\ServiceProvider\AbstractServiceProvider;
10
11
class IntentServiceProvider extends AbstractServiceProvider
12
{
13
    protected $provides = [
14
        IntentManager::class,
15
    ];
16
17
    private $intents;
18
    private $fallbackIntent;
19
20
    public function __construct(array $intents, string $fallbackIntent = FallbackIntent::class)
21
    {
22
        $this->intents = $intents;
23
        $this->fallbackIntent = $fallbackIntent;
24
    }
25
26
    /**
27
     * Use the register method to register items with the container via the
28
     * protected $this->container property or the `getContainer` method
29
     * from the ContainerAwareTrait.
30
     *
31
     * @return void
32
     */
33
    public function register(): void
34
    {
35
        $manager = new IntentManager();
36
37
        foreach ($this->intents as $intent) {
38
            $manager->add($this->getContainer()->get($intent));
39
        }
40
41
        $manager->setFallbackIntent($this->getContainer()->get($this->fallbackIntent));
42
43
        $this->getContainer()->add(IntentManager::class, $manager);
44
    }
45
}
46