diff --git a/src/Plugin.php b/src/Plugin.php index 3c36543..afd75bc 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -48,6 +48,8 @@ class Plugin implements PluginEntryPointInterface $registration->registerHooksFromClass(ReturnTypeProvider\RedirectReturnTypeProvider::class); require_once 'ReturnTypeProvider/ViewReturnTypeProvider.php'; $registration->registerHooksFromClass(ReturnTypeProvider\ViewReturnTypeProvider::class); + require_once 'ReturnTypeProvider/AppReturnTypeProvider.php'; + $registration->registerHooksFromClass(ReturnTypeProvider\AppReturnTypeProvider::class); require_once 'AppInterfaceProvider.php'; $registration->registerHooksFromClass(AppInterfaceProvider::class); require_once 'PropertyProvider/ModelPropertyProvider.php'; diff --git a/src/ReturnTypeProvider/AppReturnTypeProvider.php b/src/ReturnTypeProvider/AppReturnTypeProvider.php index 13b5e9b..57d1b40 100644 --- a/src/ReturnTypeProvider/AppReturnTypeProvider.php +++ b/src/ReturnTypeProvider/AppReturnTypeProvider.php @@ -6,6 +6,7 @@ use Psalm\CodeLocation; use Psalm\Context; use Psalm\Plugin\Hook\FunctionReturnTypeProviderInterface; use Psalm\StatementsSource; +use Psalm\Type; use Psalm\Type\Atomic\TNamedObject; use Psalm\Type\Union; @@ -32,8 +33,15 @@ final class AppReturnTypeProvider implements FunctionReturnTypeProviderInterface } // @todo: this should really proxy to \Illuminate\Foundation\Application::make, but i was struggling with that - return new Union([ - new TNamedObject($call_args[0]->value), - ]); + + $firstArgType = $statements_source->getNodeTypeProvider()->getType($call_args[0]->value); + + if ($firstArgType && $firstArgType->isSingleStringLiteral()) { + return new Union([ + new TNamedObject($firstArgType->getSingleStringLiteral()->value), + ]); + } + + return Type::getMixed(); } } diff --git a/tests/acceptance/Container.feature b/tests/acceptance/Container.feature index 164f336..e0104b6 100644 --- a/tests/acceptance/Container.feature +++ b/tests/acceptance/Container.feature @@ -54,9 +54,6 @@ Feature: Container """