Skip to content

Commit 063c828

Browse files
committed
Revert "Made ConsoleApplicationResolver lazier"
This reverts commit 9251db0.
1 parent b450ec4 commit 063c828

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

src/Symfony/ConsoleApplicationResolver.php

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
use PHPStan\Reflection\ClassReflection;
66
use PHPStan\ShouldNotHappenException;
77
use PHPStan\Type\ObjectType;
8-
use Symfony\Component\Console\Application;
98
use function file_exists;
109
use function get_class;
1110
use function is_readable;
1211

1312
final 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 */
2016
private $consoleApplication;
2117

2218
public 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)
3938
return 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
*/
6644
public function findCommands(ClassReflection $classReflection): array
6745
{
68-
$consoleApplication = $this->getConsoleApplication();
69-
if ($consoleApplication === null) {
46+
if ($this->consoleApplication === null) {
7047
return [];
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) {
8057
if (!$classType->isSuperTypeOf(new ObjectType(get_class($command)))->yes()) {
8158
continue;
8259
}

0 commit comments

Comments
 (0)