Total Complexity | 9 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
10 | class Compiler |
||
11 | { |
||
12 | /** |
||
13 | * @var Reflection |
||
14 | */ |
||
15 | private $reflection; |
||
16 | private $classes = []; |
||
17 | private $variadic = []; |
||
18 | |||
19 | public function __construct(Reflection $reflection) |
||
20 | { |
||
21 | 15 | $this->reflection = $reflection; |
|
22 | } |
||
23 | 15 | ||
24 | 15 | public function autowire(string $name): self |
|
25 | { |
||
26 | 9 | if (!$this->reflection->isInstantiable($name)) { |
|
27 | return $this; |
||
28 | 9 | } |
|
29 | 3 | if ($this->reflection->isVariadic($name)) { |
|
30 | $this->variadic[] = $name; |
||
31 | 6 | } |
|
32 | 3 | $this->classes[$name] = $this->reflection->getDependencies($name); |
|
33 | return $this; |
||
34 | 6 | } |
|
35 | 6 | ||
36 | 6 | public function compile(): string |
|
37 | { |
||
38 | return "<?php |
||
39 | |||
40 | 9 | declare(strict_types=1); |
|
41 | |||
42 | 9 | return [{$this->compileClasses()} |
|
43 | 9 | ];"; |
|
44 | } |
||
45 | |||
46 | 3 | private function compileClasses(): string |
|
61 | } |
||
62 | 15 | ||
63 | private function getClass($name): string |
||
64 | 15 | { |
|
71 |