Skip to content

Commit 52ad6de

Browse files
committed
Fallback to default helper set when no application loader is provided
1 parent d6ea162 commit 52ad6de

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Type/Symfony/CommandGetHelperDynamicReturnTypeExtension.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Type\Type;
1212
use PHPStan\Type\TypeCombinator;
1313
use PHPStan\Type\TypeUtils;
14+
use Symfony\Component\Console\Application;
1415
use Throwable;
1516
use function count;
1617
use function get_class;
@@ -55,8 +56,19 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
5556
}
5657
$argName = $argStrings[0]->getValue();
5758

59+
$commands = $this->consoleApplicationResolver->findCommands($classReflection);
60+
if (count($commands) === 0) {
61+
$consoleApplication = new Application();
62+
63+
if ($consoleApplication->getHelperSet()->has($argName) === false) {
64+
return $defaultReturnType;
65+
}
66+
67+
return new ObjectType(get_class($consoleApplication->getHelperSet()->get($argName)));
68+
}
69+
5870
$returnTypes = [];
59-
foreach ($this->consoleApplicationResolver->findCommands($classReflection) as $command) {
71+
foreach ($commands as $command) {
6072
try {
6173
$command->mergeApplicationDefinition();
6274
$returnTypes[] = new ObjectType(get_class($command->getHelper($argName)));

0 commit comments

Comments
 (0)