55use PHPStan \Reflection \ClassReflection ;
66use PHPStan \ShouldNotHappenException ;
77use PHPStan \Type \ObjectType ;
8- use Symfony \Component \Console \Application ;
98use function file_exists ;
109use function get_class ;
1110use function is_readable ;
1211
1312final class ConsoleApplicationResolver
1413{
1514
16- /** @var string|null */
17- private $ consoleApplicationLoader ;
18-
19- /** @var \Symfony\Component\Console\Application|false|null */
15+ /** @var \Symfony\Component\Console\Application|null */
2016private $ consoleApplication ;
2117
2218public function __construct (?string $ consoleApplicationLoader )
2319{
24- $ this ->consoleApplicationLoader = $ consoleApplicationLoader ;
20+ if ($ consoleApplicationLoader === null ) {
21+ return ;
22+ }
23+ $ this ->consoleApplication = $ this ->loadConsoleApplication ($ consoleApplicationLoader );
2524}
2625
2726/**
@@ -39,34 +38,12 @@ private function loadConsoleApplication(string $consoleApplicationLoader)
3938return require $ consoleApplicationLoader ;
4039}
4140
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-
6341/**
6442 * @return \Symfony\Component\Console\Command\Command[]
6543 */
6644public function findCommands (ClassReflection $ classReflection ): array
6745{
68- $ consoleApplication = $ this ->getConsoleApplication ();
69- if ($ consoleApplication === null ) {
46+ if ($ this ->consoleApplication === null ) {
7047return [];
7148}
7249
@@ -76,7 +53,7 @@ public function findCommands(ClassReflection $classReflection): array
7653}
7754
7855$ commands = [];
79- foreach ($ consoleApplication ->all () as $ name => $ command ) {
56+ foreach ($ this -> consoleApplication ->all () as $ name => $ command ) {
8057if (!$ classType ->isSuperTypeOf (new ObjectType (get_class ($ command )))->yes ()) {
8158continue ;
8259}
0 commit comments