Passed
Push — compile_injector ( fb8411 )
by Akihito
11:57
created

LazyModule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 2
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package;
6
7
use BEAR\AppMeta\AbstractAppMeta;
8
use BEAR\Package\Module\ResourceObjectModule;
9
use BEAR\Package\Module\ScriptinjectorModule;
10
use Ray\Compiler\LazyModuleInterface;
11
use Ray\Di\AbstractModule;
12
13
class LazyModule implements LazyModuleInterface
14
{
15
    /** @var AbstractAppMeta */
16
    private $appMeta;
17
18
    /** @var string */
19
    private $context;
20
21
    /** @var string */
22
    private $scriptDir;
23
24
    /** @var bool */
25
    private $strict;
26
27
    public function __construct(AbstractAppMeta $appMeta, string $context, string $scriptDir, bool $strict = false)
28
    {
29
        $this->appMeta = $appMeta;
30
        $this->context = $context;
31
        $this->scriptDir = $scriptDir;
32
        $this->strict = $strict;
33
    }
34
35
    public function __invoke(): AbstractModule
36
    {
37
        $module = new ScriptinjectorModule($this->scriptDir, (new Module())($this->appMeta, $this->context));
38
        if ($this->strict) {
39
            $module->install(new ResourceObjectModule($this->appMeta->getResourceListGenerator()));
40
        }
41
42
        return $module;
43
    }
44
}
45