1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gacela\Console\Domain\AllAppModules; |
6
|
|
|
|
7
|
|
|
use Gacela\Framework\ClassResolver\Config\ConfigNotFoundException; |
8
|
|
|
use Gacela\Framework\ClassResolver\Config\ConfigResolver; |
9
|
|
|
use Gacela\Framework\ClassResolver\DependencyProvider\DependencyProviderNotFoundException; |
10
|
|
|
use Gacela\Framework\ClassResolver\DependencyProvider\DependencyProviderResolver; |
11
|
|
|
use Gacela\Framework\ClassResolver\Factory\FactoryNotFoundException; |
12
|
|
|
use Gacela\Framework\ClassResolver\Factory\FactoryResolver; |
13
|
|
|
use ReflectionClass; |
14
|
|
|
|
15
|
|
|
final class AppModuleCreator |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param class-string $facadeClass |
19
|
|
|
*/ |
20
|
7 |
|
public function fromClass(string $facadeClass): AppModule |
21
|
|
|
{ |
22
|
7 |
|
return new AppModule( |
23
|
7 |
|
$this->moduleName($facadeClass), |
24
|
7 |
|
$facadeClass, |
25
|
7 |
|
$this->findFactory($facadeClass), |
|
|
|
|
26
|
7 |
|
$this->findConfig($facadeClass), |
|
|
|
|
27
|
7 |
|
$this->findDependencyProvider($facadeClass), |
|
|
|
|
28
|
7 |
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param class-string $facadeClass |
33
|
|
|
*/ |
34
|
7 |
|
private function moduleName(string $facadeClass): string |
35
|
|
|
{ |
36
|
7 |
|
$parts = explode('\\', $facadeClass); |
37
|
7 |
|
array_pop($parts); |
38
|
|
|
|
39
|
7 |
|
return (string)end($parts); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param class-string $facadeClass |
44
|
|
|
*/ |
45
|
7 |
|
private function findFactory(string $facadeClass): ?string |
46
|
|
|
{ |
47
|
|
|
try { |
48
|
7 |
|
$resolver = (new FactoryResolver())->resolve($facadeClass); |
49
|
|
|
|
50
|
7 |
|
if ((new ReflectionClass($resolver))->isAnonymous()) { |
51
|
3 |
|
throw new FactoryNotFoundException($facadeClass); |
52
|
|
|
} |
53
|
|
|
|
54
|
6 |
|
return $resolver::class; |
55
|
3 |
|
} catch (FactoryNotFoundException $e) { |
56
|
3 |
|
return null; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param class-string $facadeClass |
62
|
|
|
*/ |
63
|
7 |
|
private function findConfig(string $facadeClass): ?string |
64
|
|
|
{ |
65
|
|
|
try { |
66
|
7 |
|
$resolver = (new ConfigResolver())->resolve($facadeClass); |
67
|
|
|
|
68
|
7 |
|
if ((new ReflectionClass($resolver))->isAnonymous()) { |
69
|
5 |
|
throw new ConfigNotFoundException($facadeClass); |
70
|
|
|
} |
71
|
|
|
|
72
|
4 |
|
return $resolver::class; |
73
|
5 |
|
} catch (ConfigNotFoundException $e) { |
74
|
5 |
|
return null; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param class-string $facadeClass |
80
|
|
|
*/ |
81
|
7 |
|
private function findDependencyProvider(string $facadeClass): ?string |
82
|
|
|
{ |
83
|
|
|
try { |
84
|
7 |
|
$resolver = (new DependencyProviderResolver())->resolve($facadeClass); |
85
|
|
|
|
86
|
6 |
|
if ((new ReflectionClass($resolver))->isAnonymous()) { |
87
|
|
|
throw new DependencyProviderNotFoundException($resolver); |
88
|
|
|
} |
89
|
6 |
|
return $resolver::class; |
90
|
3 |
|
} catch (DependencyProviderNotFoundException $e) { |
91
|
3 |
|
return null; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.