Total Complexity | 10 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
11 | class Reflection |
||
12 | { |
||
13 | private static $dependencies = []; |
||
14 | private static $instantiable = []; |
||
15 | |||
16 | /** |
||
17 | * @param string $name |
||
18 | * @return array<string> |
||
19 | * @internal |
||
20 | */ |
||
21 | public function getDependencies(string $name): array |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param string $name |
||
31 | * @return bool |
||
32 | * @internal |
||
33 | */ |
||
34 | public function isInstantiable(string $name): bool |
||
35 | { |
||
36 | if (!array_key_exists($name, self::$instantiable)) { |
||
37 | $this->load($name); |
||
38 | } |
||
39 | return self::$instantiable[$name]; |
||
40 | } |
||
41 | |||
42 | private function load(string $name): void |
||
43 | { |
||
44 | try { |
||
45 | $class = new ReflectionClass($name); |
||
46 | self::$instantiable[$name] = $class->isInstantiable(); |
||
47 | self::$dependencies[$name] = self::getMethodParameters($class->getConstructor()); |
||
48 | } catch (ReflectionException $exception) { |
||
49 | self::$dependencies[$name] = []; |
||
50 | self::$instantiable[$name] = false; |
||
51 | } |
||
52 | } |
||
53 | |||
54 | private static function getMethodParameters(?ReflectionMethod $method): array |
||
64 | } |
||
65 | } |
||
66 |