From 52ad6deb95bd29a84bd6fd9e9f407b78703be3f5 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 12 Nov 2022 19:34:59 +0100 Subject: [PATCH] Fallback to default helper set when no application loader is provided --- .../CommandGetHelperDynamicReturnTypeExtension.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Type/Symfony/CommandGetHelperDynamicReturnTypeExtension.php b/src/Type/Symfony/CommandGetHelperDynamicReturnTypeExtension.php index db2348e3..a2cbbf76 100644 --- a/src/Type/Symfony/CommandGetHelperDynamicReturnTypeExtension.php +++ b/src/Type/Symfony/CommandGetHelperDynamicReturnTypeExtension.php @@ -11,6 +11,7 @@ use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; use PHPStan\Type\TypeUtils; +use Symfony\Component\Console\Application; use Throwable; use function count; use function get_class; @@ -55,8 +56,19 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method } $argName = $argStrings[0]->getValue(); + $commands = $this->consoleApplicationResolver->findCommands($classReflection); + if (count($commands) === 0) { + $consoleApplication = new Application(); + + if ($consoleApplication->getHelperSet()->has($argName) === false) { + return $defaultReturnType; + } + + return new ObjectType(get_class($consoleApplication->getHelperSet()->get($argName))); + } + $returnTypes = []; - foreach ($this->consoleApplicationResolver->findCommands($classReflection) as $command) { + foreach ($commands as $command) { try { $command->mergeApplicationDefinition(); $returnTypes[] = new ObjectType(get_class($command->getHelper($argName)));