fix: get the actual class of the app depending on if its lumen vs. laravel

This commit is contained in:
Feek 2020-05-08 18:25:54 -07:00
parent 1010f65905
commit 6a48722ab7
2 changed files with 18 additions and 1 deletions

View File

@ -4,11 +4,13 @@ namespace Psalm\LaravelPlugin\ReturnTypeProvider;
use Psalm\CodeLocation; use Psalm\CodeLocation;
use Psalm\Context; use Psalm\Context;
use Psalm\LaravelPlugin\ApplicationHelper;
use Psalm\Plugin\Hook\FunctionReturnTypeProviderInterface; use Psalm\Plugin\Hook\FunctionReturnTypeProviderInterface;
use Psalm\StatementsSource; use Psalm\StatementsSource;
use Psalm\Type; use Psalm\Type;
use Psalm\Type\Atomic\TNamedObject; use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Union; use Psalm\Type\Union;
use function get_class;
final class AppReturnTypeProvider implements FunctionReturnTypeProviderInterface final class AppReturnTypeProvider implements FunctionReturnTypeProviderInterface
{ {
@ -28,7 +30,7 @@ final class AppReturnTypeProvider implements FunctionReturnTypeProviderInterface
{ {
if (!$call_args) { if (!$call_args) {
return new Union([ return new Union([
new TNamedObject(\Illuminate\Contracts\Foundation\Application::class), new TNamedObject(get_class(ApplicationHelper::getApp())),
]); ]);
} }

View File

@ -63,3 +63,18 @@ Feature: Container
""" """
When I run Psalm When I run Psalm
Then I see no errors Then I see no errors
Scenario: app helper can be chained with make / makeWith
Given I have the following code
"""
<?php
function testMake(): \Illuminate\Routing\Redirector {
return app()->make(\Illuminate\Routing\Redirector::class);
}
function testMakeWith(): \Illuminate\Routing\Redirector {
return app()->makeWith(\Illuminate\Routing\Redirector::class);
}
"""
When I run Psalm
Then I see no errors