Completed
Push — grapher ( 6c7433 )
by Akihito
01:47
created

Grapher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 0
loc 55
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A __wakeup() 0 11 2
A newInstanceArgs() 0 4 1
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
     * @param string         $tmpDir Writable directory for generated AOP classes
0 ignored issues
show
Bug introduced by
There is no parameter named $tmpDir. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

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