Completed
Push — 2.x ( 39dc4e...b7fd10 )
by Akihito
01:28
created

Grapher::__wakeup()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Ray\Aop\Compiler;
8
9
final class Grapher
10
{
11
    /**
12
     * @var string
13
     */
14
    private $classDir;
15
16
    /**
17
     * @var Container
18
     */
19
    private $container;
20
21
    /**
22
     * @param AbstractModule $module Binding module
23
     */
24
    public function __construct(AbstractModule $module, string $classDir)
25
    {
26
        $module->install(new AssistedModule);
0 ignored issues
show
Documentation introduced by
new \Ray\Di\AssistedModule() is of type object<Ray\Di\AssistedModule>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
        $this->container = $module->getContainer();
28
        $this->classDir = $classDir;
29
        $this->container->weaveAspects(new Compiler($this->classDir));
30
31
        // builtin injection
32
        (new Bind($this->container, InjectorInterface::class))->toInstance(new Injector($module));
33
    }
34
35
    /**
36
     * Wakeup
37
     */
38
    public function __wakeup()
39
    {
40
        spl_autoload_register(
41
            function (string $class) {
42
                $file = sprintf('%s/%s.php', $this->classDir, str_replace('\\', '_', $class));
43
                if (file_exists($file)) {
44
                    include $file; //@codeCoverageIgnore
45
                }
46
            }
47
        );
48
    }
49
50
    /**
51
     * Build an object graph with give constructor parameters
52
     *
53
     * @param string $class  class name
54
     * @param array  $params constuct paramteters
55
     */
56
    public function newInstanceArgs(string $class, array $params)
57
    {
58
        return $this->container->getInstanceWithArgs($class, $params);
59
    }
60
}
61