mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-11-26 20:34:48 +01:00
feature: redirect return types
This commit is contained in:
parent
f55c67822f
commit
6c0b792d9a
@ -58,6 +58,8 @@ abstract class AbstractPlugin implements PluginEntryPointInterface
|
||||
$registration->registerHooksFromClass(ReturnTypeProvider\AuthReturnTypeProvider::class);
|
||||
require_once 'ReturnTypeProvider/TransReturnTypeProvider.php';
|
||||
$registration->registerHooksFromClass(ReturnTypeProvider\TransReturnTypeProvider::class);
|
||||
require_once 'ReturnTypeProvider/RedirectReturnTypeProvider.php';
|
||||
$registration->registerHooksFromClass(ReturnTypeProvider\RedirectReturnTypeProvider::class);
|
||||
require_once 'ReturnTypeProvider/ViewReturnTypeProvider.php';
|
||||
$registration->registerHooksFromClass(ReturnTypeProvider\ViewReturnTypeProvider::class);
|
||||
require_once 'AppInterfaceProvider.php';
|
||||
|
41
src/ReturnTypeProvider/RedirectReturnTypeProvider.php
Normal file
41
src/ReturnTypeProvider/RedirectReturnTypeProvider.php
Normal 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,
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user