feature: redirect return types

This commit is contained in:
Feek 2020-04-08 00:22:28 -07:00
parent f55c67822f
commit 6c0b792d9a
2 changed files with 43 additions and 0 deletions

View File

@ -58,6 +58,8 @@ abstract class AbstractPlugin implements PluginEntryPointInterface
$registration->registerHooksFromClass(ReturnTypeProvider\AuthReturnTypeProvider::class); $registration->registerHooksFromClass(ReturnTypeProvider\AuthReturnTypeProvider::class);
require_once 'ReturnTypeProvider/TransReturnTypeProvider.php'; require_once 'ReturnTypeProvider/TransReturnTypeProvider.php';
$registration->registerHooksFromClass(ReturnTypeProvider\TransReturnTypeProvider::class); $registration->registerHooksFromClass(ReturnTypeProvider\TransReturnTypeProvider::class);
require_once 'ReturnTypeProvider/RedirectReturnTypeProvider.php';
$registration->registerHooksFromClass(ReturnTypeProvider\RedirectReturnTypeProvider::class);
require_once 'ReturnTypeProvider/ViewReturnTypeProvider.php'; require_once 'ReturnTypeProvider/ViewReturnTypeProvider.php';
$registration->registerHooksFromClass(ReturnTypeProvider\ViewReturnTypeProvider::class); $registration->registerHooksFromClass(ReturnTypeProvider\ViewReturnTypeProvider::class);
require_once 'AppInterfaceProvider.php'; require_once 'AppInterfaceProvider.php';

View File

@ -0,0 +1,41 @@
<?php declare(strict_types=1);
namespace Psalm\LaravelPlugin\ReturnTypeProvider;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Psalm\CodeLocation;
use Psalm\Context;
use Psalm\Plugin\Hook\FunctionReturnTypeProviderInterface;
use Psalm\StatementsSource;
use Psalm\Type;
class RedirectReturnTypeProvider implements FunctionReturnTypeProviderInterface
{
/**
* @return array<string>
*/
public static function getFunctionIds(): array
{
return ['redirect'];
}
/**
* @param array<PhpParser\Node\Arg> $call_args
*
* @return ?Type\Union
*/
public static function getFunctionReturnType(StatementsSource $statements_source, string $function_id, array $call_args, Context $context, CodeLocation $code_location)
{
if (!$call_args) {
return new Type\Union([
new Type\Atomic\TNamedObject(Redirector::class)
]);
}
return new Type\Union([
RedirectResponse::class,
]);
}
}