2019-03-01 14:57:10 +01:00
|
|
|
<?php
|
2019-05-10 00:58:30 +02:00
|
|
|
namespace Psalm\Test\Config\Plugin\Hook;
|
2019-03-01 14:57:10 +01:00
|
|
|
|
|
|
|
use PhpParser;
|
|
|
|
use Psalm\CodeLocation;
|
|
|
|
use Psalm\Context;
|
2019-03-23 19:27:54 +01:00
|
|
|
use Psalm\Plugin\Hook\FunctionExistenceProviderInterface;
|
|
|
|
use Psalm\Plugin\Hook\FunctionParamsProviderInterface;
|
|
|
|
use Psalm\Plugin\Hook\FunctionReturnTypeProviderInterface;
|
2019-03-01 14:57:10 +01:00
|
|
|
use Psalm\StatementsSource;
|
2019-03-23 19:27:54 +01:00
|
|
|
use Psalm\Type;
|
2019-03-01 14:57:10 +01:00
|
|
|
|
|
|
|
class MagicFunctionProvider implements
|
|
|
|
FunctionExistenceProviderInterface,
|
|
|
|
FunctionParamsProviderInterface,
|
|
|
|
FunctionReturnTypeProviderInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return array<string>
|
|
|
|
*/
|
|
|
|
public static function getFunctionIds() : array
|
|
|
|
{
|
|
|
|
return ['magicfunction'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ?bool
|
|
|
|
*/
|
|
|
|
public static function doesFunctionExist(
|
2020-08-10 05:19:59 +02:00
|
|
|
StatementsSource $statements_source,
|
2019-03-01 14:57:10 +01:00
|
|
|
string $function_id,
|
|
|
|
CodeLocation $code_location = null
|
|
|
|
) {
|
|
|
|
return $function_id === 'magicfunction';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<PhpParser\Node\Arg> $call_args
|
2019-03-23 19:27:54 +01:00
|
|
|
*
|
2019-03-01 14:57:10 +01:00
|
|
|
* @return ?array<int, \Psalm\Storage\FunctionLikeParameter>
|
|
|
|
*/
|
|
|
|
public static function getFunctionParams(
|
|
|
|
StatementsSource $statements_source,
|
|
|
|
string $function_id,
|
|
|
|
array $call_args,
|
|
|
|
Context $context = null,
|
|
|
|
CodeLocation $code_location = null
|
|
|
|
) {
|
|
|
|
return [new \Psalm\Storage\FunctionLikeParameter('first', false, Type::getString())];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<PhpParser\Node\Arg> $call_args
|
2019-03-23 19:27:54 +01:00
|
|
|
*
|
2019-03-01 14:57:10 +01:00
|
|
|
* @return ?Type\Union
|
|
|
|
*/
|
|
|
|
public static function getFunctionReturnType(
|
2020-08-10 05:19:59 +02:00
|
|
|
StatementsSource $statements_source,
|
2019-03-01 14:57:10 +01:00
|
|
|
string $function_id,
|
|
|
|
array $call_args,
|
|
|
|
Context $context,
|
|
|
|
CodeLocation $code_location
|
|
|
|
) {
|
|
|
|
return Type::getString();
|
|
|
|
}
|
|
|
|
}
|