ContainerFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 2
b 0
f 0
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 1
A getModule() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Ray\Aop\Compiler;
8
9
use function array_shift;
10
11
/**
12
 * @psalm-import-type ModuleList from Types
13
 * @psalm-import-type ScriptDir from Types
14
 */
15
final class ContainerFactory
16
{
17
    /**
18
     * @param AbstractModule|ModuleList|null $module   Module(s)
0 ignored issues
show
Bug introduced by
The type Ray\Di\ModuleList was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
     * @param ScriptDir                      $classDir
0 ignored issues
show
Bug introduced by
The type Ray\Di\ScriptDir was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
     */
21
    public function __invoke($module, string $classDir): Container
22
    {
23
        $oneModule = $this->getModule($module);
24
        // install built-in module
25
        $appModule = (new BuiltinModule())($oneModule);
26
        $container = $appModule->getContainer();
27
        // Compile null objects
28
        (new CompileNullObject())($container, $classDir);
29
        // Compile aspects
30
        /** @psalm-suppress InvalidArgument */
31
        $container->weaveAspects(new Compiler($classDir));
32
33
        return $container;
34
    }
35
36
    /**
37
     * @param AbstractModule|ModuleList|null $module Module(s)
38
     */
39
    private function getModule($module): AbstractModule
40
    {
41
        if ($module instanceof AbstractModule) {
42
            return $module;
43
        }
44
45
        if ($module === null) {
0 ignored issues
show
introduced by
The condition $module === null is always true.
Loading history...
46
            return new NullModule();
47
        }
48
49
        $modules = $module;
50
        $oneModule = array_shift($modules);
51
        foreach ($modules as $module) {
0 ignored issues
show
introduced by
$module is overwriting one of the parameters of this function.
Loading history...
52
            $oneModule->install($module);
53
        }
54
55
        return $oneModule;
56
    }
57
}
58