Boot   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getInjector() 0 14 2
1
<?php
2
/**
3
 * This file is part of the BEAR.Middleware package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Middleware;
8
9
use BEAR\AppMeta\AbstractAppMeta;
10
use BEAR\Middleware\Module\MiddlewareModule;
11
use BEAR\Middleware\Module\StreamModule;
12
use BEAR\Package\Module;
13
use Ray\Compiler\DiCompiler;
14
use Ray\Compiler\Exception\NotCompiled;
15
use Ray\Compiler\ScriptInjector;
16
use Ray\Di\InjectorInterface;
17
18
class Boot
19
{
20 3
    public function getInjector(AbstractAppMeta $appMeta, $contexts)
21
    {
22
        try {
23 3
            $injector = (new ScriptInjector($appMeta->tmpDir))->getInstance(InjectorInterface::class);
24 3
        } catch (NotCompiled $e) {
25 3
            $module = (new Module)($appMeta, $contexts);
26 2
            $module->override(new MiddlewareModule());
27 2
            $compiler = new DiCompiler(new StreamModule($module), $appMeta->tmpDir);
28 2
            $compiler->compile();
29 2
            $injector = (new ScriptInjector($appMeta->tmpDir))->getInstance(InjectorInterface::class);
30
        }
31
32 2
        return $injector;
33
    }
34
}
35