5
5
use PHPStan \Reflection \ClassReflection ;
6
6
use PHPStan \ShouldNotHappenException ;
7
7
use PHPStan \Type \ObjectType ;
8
- use Symfony \Component \Console \Application ;
9
8
use function file_exists ;
10
9
use function get_class ;
11
10
use function is_readable ;
12
11
13
12
final class ConsoleApplicationResolver
14
13
{
15
14
16
- /** @var string|null */
17
- private $ consoleApplicationLoader ;
18
-
19
- /** @var \Symfony\Component\Console\Application|false|null */
15
+ /** @var \Symfony\Component\Console\Application|null */
20
16
private $ consoleApplication ;
21
17
22
18
public function __construct (?string $ consoleApplicationLoader )
23
19
{
24
- $ this ->consoleApplicationLoader = $ consoleApplicationLoader ;
20
+ if ($ consoleApplicationLoader === null ) {
21
+ return ;
22
+ }
23
+ $ this ->consoleApplication = $ this ->loadConsoleApplication ($ consoleApplicationLoader );
25
24
}
26
25
27
26
/**
@@ -39,34 +38,12 @@ private function loadConsoleApplication(string $consoleApplicationLoader)
39
38
return require $ consoleApplicationLoader ;
40
39
}
41
40
42
- public function getConsoleApplication (): ?Application
43
- {
44
- if ($ this ->consoleApplication === false ) {
45
- return null ;
46
- }
47
-
48
- if ($ this ->consoleApplication !== null ) {
49
- return $ this ->consoleApplication ;
50
- }
51
-
52
- if ($ this ->consoleApplicationLoader === null ) {
53
- $ this ->consoleApplication = false ;
54
-
55
- return null ;
56
- }
57
-
58
- $ this ->consoleApplication = $ this ->loadConsoleApplication ($ this ->consoleApplicationLoader );
59
-
60
- return $ this ->consoleApplication ;
61
- }
62
-
63
41
/**
64
42
* @return \Symfony\Component\Console\Command\Command[]
65
43
*/
66
44
public function findCommands (ClassReflection $ classReflection ): array
67
45
{
68
- $ consoleApplication = $ this ->getConsoleApplication ();
69
- if ($ consoleApplication === null ) {
46
+ if ($ this ->consoleApplication === null ) {
70
47
return [];
71
48
}
72
49
@@ -76,7 +53,7 @@ public function findCommands(ClassReflection $classReflection): array
76
53
}
77
54
78
55
$ commands = [];
79
- foreach ($ consoleApplication ->all () as $ name => $ command ) {
56
+ foreach ($ this -> consoleApplication ->all () as $ name => $ command ) {
80
57
if (!$ classType ->isSuperTypeOf (new ObjectType (get_class ($ command )))->yes ()) {
81
58
continue ;
82
59
}
0 commit comments