Grapher   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 50
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A __wakeup() 0 7 2
A newInstanceArgs() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Ray\Aop\Compiler;
8
9
use function file_exists;
10
use function spl_autoload_register;
11
use function sprintf;
12
use function str_replace;
13
14
/**
15
 * @psalm-import-type MethodArguments from Types
16
 * @psalm-import-type ScriptDir from Types
17
 */
18
final class Grapher
19
{
20
    /** @var ScriptDir */
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...
21
    private $classDir;
22
23
    /** @var Container */
24
    private $container;
25
26
    /**
27
     * @param AbstractModule $module   Binding module
28
     * @param ScriptDir      $classDir Class directory
29
     */
30
    public function __construct(AbstractModule $module, string $classDir)
31
    {
32
        $module->install(new AssistedModule());
33
        $this->container = $module->getContainer();
34
        $this->classDir = $classDir;
0 ignored issues
show
Documentation Bug introduced by
It seems like $classDir of type string is incompatible with the declared type Ray\Di\ScriptDir of property $classDir.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
        /** @psalm-suppress InvalidArgument */
36
        $this->container->weaveAspects(new Compiler($this->classDir));
37
38
        // builtin injection
39
        (new Bind($this->container, InjectorInterface::class))->toInstance(new Injector($module));
40
    }
41
42
    /**
43
     * Wakeup
44
     */
45
    public function __wakeup()
46
    {
47
        spl_autoload_register(
48
            function (string $class): void {
49
                $file = sprintf('%s/%s.php', $this->classDir, str_replace('\\', '_', $class));
50
                if (file_exists($file)) {
51
                    include $file; //@codeCoverageIgnore
52
                }
53
            }
54
        );
55
    }
56
57
    /**
58
     * Build an object graph with give constructor parameters
59
     *
60
     * @param string      $class  class name
61
     * @param list<mixed> $params construct parameters (MethodArguments)
0 ignored issues
show
Bug introduced by
The type Ray\Di\list 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...
62
     *
63
     * @return mixed
64
     */
65
    public function newInstanceArgs(string $class, array $params)
66
    {
67
        return $this->container->getInstanceWithArgs($class, $params);
68
    }
69
}
70