Passed
Push — master ( f3c67a...8e7fe7 )
by Evgeniy
14:18 queued 10s
created

DefinitionGenerator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 3
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI;
6
7
use Cekta\DI\Strategy\Definition\Factory;
8
9
class DefinitionGenerator
10
{
11
    /**
12
     * @var Reflection
13
     */
14
    private $reflection;
15
16
    public function __construct(Reflection $reflection)
17
    {
18
        $this->reflection = $reflection;
19
    }
20
21
    public function __invoke(string ...$classes): string
22
    {
23
        $factory = Factory::class;
24
        $body = '';
25
        foreach ($classes as $class) {
26
            if ($this->reflection->isInstantiable($class)) {
27
                $dependencies = var_export($this->reflection->getDependencies($class), true);
28
                $body .= PHP_EOL . "'{$class}' => new $factory('$class', ...$dependencies)," . PHP_EOL;
29
            }
30
        }
31
        return "<?php
32
33
declare(strict_types=1);
34
35
return [{$body}];";
36
    }
37
}
38