Passed
Pull Request — master (#105)
by Evgeniy
08:08 queued 04:03
created

Compiler::compileClasses()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 2
rs 9.9
c 0
b 0
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