Completed
Push — master ( 9b6fee...2a88b7 )
by Vladimir
05:31
created

Factory::create()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 19
nc 1
nop 3
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
ccs 0
cts 15
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Toolbelt;
6
7
use Dotenv\Dotenv;
8
use League\Container\Container;
9
use League\Flysystem\Adapter\Local;
10
use FondBot\Toolbelt\Commands\MakeIntent;
11
use League\Container\ReflectionContainer;
12
use Symfony\Component\Console\Application;
13
use FondBot\Toolbelt\Commands\MakeInteraction;
14
use FondBot\Filesystem\FilesystemServiceProvider;
15
16
class Factory
17
{
18
    public static function create(
19
        Container $container,
20
        string $basePath,
21
        string $resourcesPath
22
    ): Kernel {
23
        $dotenv = new Dotenv($basePath);
24
        $dotenv->load();
25
26
        $container->delegate(new ReflectionContainer);
27
28
        $container->add('base_path', $basePath);
29
        $container->add('resources_path', $resourcesPath);
30
31
        // Load service providers
32
        $container->addServiceProvider(new FilesystemServiceProvider(new Local($basePath)));
33
34
        // Boot kernel
35
        $kernel = new Kernel($container);
36
37
        // Boot console application
38
        $console = new Application('FondBot', \FondBot\Application\Kernel::VERSION);
39
        $console->addCommands([
40
            new MakeIntent($kernel),
41
            new MakeInteraction($kernel),
42
        ]);
43
44
        $container->add(Kernel::class, $kernel);
45
        $container->add('console', $console);
46
47
        return $kernel;
48
    }
49
}
50