Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e5459eb

Browse files
ConsoleApplicationResolver made lazy
1 parent 016e441 commit e5459eb

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

‎src/Symfony/ConsoleApplicationResolver.php‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,47 @@
1616
final class ConsoleApplicationResolver
1717
{
1818

19+
/** @var string|null */
20+
private $consoleApplicationLoader;
21+
1922
/** @var Application|null */
2023
private $consoleApplication;
2124

2225
public function __construct(Configuration $configuration)
2326
{
24-
$consoleApplicationLoader = $configuration->getConsoleApplicationLoader();
25-
if ($consoleApplicationLoader === null) {
26-
return;
27-
}
28-
$this->consoleApplication = $this->loadConsoleApplication($consoleApplicationLoader);
27+
$this->consoleApplicationLoader = $configuration->getConsoleApplicationLoader();
2928
}
3029

3130
/**
3231
* @return Application|null
3332
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
3433
*/
35-
private function loadConsoleApplication(string$consoleApplicationLoader)
34+
private function getConsoleApplication()
3635
{
37-
if (!file_exists($consoleApplicationLoader)
38-
|| !is_readable($consoleApplicationLoader)
36+
if ($this->consoleApplicationLoader === null) {
37+
return null;
38+
}
39+
40+
if ($this->consoleApplication !== null) {
41+
return $this->consoleApplication;
42+
}
43+
44+
if (!file_exists($this->consoleApplicationLoader)
45+
|| !is_readable($this->consoleApplicationLoader)
3946
) {
40-
throw new ShouldNotHappenException(sprintf('Cannot load console application. Check the parameters.symfony.consoleApplicationLoader setting in PHPStan\'s config. The offending value is "%s".', $consoleApplicationLoader));
47+
throw new ShouldNotHappenException(sprintf('Cannot load console application. Check the parameters.symfony.consoleApplicationLoader setting in PHPStan\'s config. The offending value is "%s".', $this->consoleApplicationLoader));
4148
}
4249

43-
return require $consoleApplicationLoader;
50+
return $this->consoleApplication = require $this->consoleApplicationLoader;
4451
}
4552

4653
/**
4754
* @return Command[]
4855
*/
4956
public function findCommands(ClassReflection $classReflection): array
5057
{
51-
if ($this->consoleApplication === null) {
58+
$consoleApplication = $this->getConsoleApplication();
59+
if ($consoleApplication === null) {
5260
return [];
5361
}
5462

@@ -58,7 +66,7 @@ public function findCommands(ClassReflection $classReflection): array
5866
}
5967

6068
$commands = [];
61-
foreach ($this->consoleApplication->all() as $name => $command) {
69+
foreach ($consoleApplication->all() as $name => $command) {
6270
$commandClass = new ObjectType(get_class($command));
6371
$isLazyCommand = (new ObjectType('Symfony\Component\Console\Command\LazyCommand'))->isSuperTypeOf($commandClass)->yes();
6472

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /