Passed
Push — master ( 772c92...f3c67a )
by Evgeniy
01:14 queued 12s
created

Compiler::autowire()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 3
rs 10
c 1
b 1
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI;
6
7
use Cekta\DI\Container\Compiled\Factory;
8
9
class Compiler
10
{
11
    /**
12
     * @var Reflection
13
     */
14
    private $reflection;
15
16 6
    public function __construct(Reflection $reflection)
17
    {
18 6
        $this->reflection = $reflection;
19 6
    }
20
21 6
    public function compile(string ...$classes): string
22
    {
23 6
        $factory = Factory::class;
24 6
        $body = '';
25 6
        foreach ($classes as $class) {
26 6
            if ($this->reflection->isInstantiable($class)) {
27 3
                $dependencies = var_export($this->reflection->getDependencies($class), true);
28 3
                $body .= PHP_EOL . "'{$class}' => new $factory('$class', ...$dependencies)," . PHP_EOL;
29
            }
30
        }
31 2
        return "<?php
32
33
declare(strict_types=1);
34
35 6
return [{$body}];";
36
    }
37
}
38