2019-03-01 14:57:10 +01:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2019-05-10 00:58:30 +02:00
|
|
|
namespace Psalm\Test\Config\Plugin\Hook;
|
2019-03-01 14:57:10 +01:00
|
|
|
|
2021-01-06 15:05:53 +01:00
|
|
|
use Psalm\Plugin\EventHandler\Event\FunctionExistenceProviderEvent;
|
|
|
|
use Psalm\Plugin\EventHandler\Event\FunctionParamsProviderEvent;
|
|
|
|
use Psalm\Plugin\EventHandler\Event\FunctionReturnTypeProviderEvent;
|
2021-06-08 04:55:21 +02:00
|
|
|
use Psalm\Plugin\EventHandler\FunctionExistenceProviderInterface;
|
|
|
|
use Psalm\Plugin\EventHandler\FunctionParamsProviderInterface;
|
|
|
|
use Psalm\Plugin\EventHandler\FunctionReturnTypeProviderInterface;
|
2021-12-03 20:11:20 +01:00
|
|
|
use Psalm\Storage\FunctionLikeParameter;
|
2019-03-23 19:27:54 +01:00
|
|
|
use Psalm\Type;
|
2021-12-13 16:28:14 +01:00
|
|
|
use Psalm\Type\Union;
|
2019-03-01 14:57:10 +01:00
|
|
|
|
|
|
|
class MagicFunctionProvider implements
|
|
|
|
FunctionExistenceProviderInterface,
|
|
|
|
FunctionParamsProviderInterface,
|
|
|
|
FunctionReturnTypeProviderInterface
|
|
|
|
{
|
|
|
|
/**
|
2020-12-29 12:42:12 +01:00
|
|
|
* @return array<lowercase-string>
|
2019-03-01 14:57:10 +01:00
|
|
|
*/
|
2021-12-05 18:51:26 +01:00
|
|
|
public static function getFunctionIds(): array
|
2019-03-01 14:57:10 +01:00
|
|
|
{
|
|
|
|
return ['magicfunction'];
|
|
|
|
}
|
|
|
|
|
2021-01-06 15:05:53 +01:00
|
|
|
public static function doesFunctionExist(FunctionExistenceProviderEvent $event): ?bool
|
|
|
|
{
|
|
|
|
$function_id = $event->getFunctionId();
|
2019-03-01 14:57:10 +01:00
|
|
|
return $function_id === 'magicfunction';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-12-04 03:37:19 +01:00
|
|
|
* @return ?array<int, FunctionLikeParameter>
|
2019-03-01 14:57:10 +01:00
|
|
|
*/
|
2021-01-06 15:05:53 +01:00
|
|
|
public static function getFunctionParams(FunctionParamsProviderEvent $event): ?array
|
|
|
|
{
|
2022-10-03 11:53:05 +02:00
|
|
|
return [new FunctionLikeParameter('first', false, Type::getString(), Type::getString())];
|
2019-03-01 14:57:10 +01:00
|
|
|
}
|
|
|
|
|
2021-12-13 16:28:14 +01:00
|
|
|
public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $event): ?Union
|
2021-01-06 15:05:53 +01:00
|
|
|
{
|
2019-03-01 14:57:10 +01:00
|
|
|
return Type::getString();
|
|
|
|
}
|
|
|
|
}
|