2019-03-01 14:57:10 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Test\Plugin\Hook;
|
|
|
|
|
|
|
|
use PhpParser;
|
|
|
|
use Psalm\CodeLocation;
|
|
|
|
use Psalm\Context;
|
2019-03-23 19:27:54 +01:00
|
|
|
use Psalm\Plugin\Hook\MethodExistenceProviderInterface;
|
|
|
|
use Psalm\Plugin\Hook\MethodParamsProviderInterface;
|
|
|
|
use Psalm\Plugin\Hook\MethodReturnTypeProviderInterface;
|
|
|
|
use Psalm\Plugin\Hook\MethodVisibilityProviderInterface;
|
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 FooMethodProvider implements
|
|
|
|
MethodExistenceProviderInterface,
|
|
|
|
MethodVisibilityProviderInterface,
|
|
|
|
MethodParamsProviderInterface,
|
|
|
|
MethodReturnTypeProviderInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return array<string>
|
|
|
|
*/
|
|
|
|
public static function getClassLikeNames() : array
|
|
|
|
{
|
|
|
|
return ['Ns\Foo'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ?bool
|
|
|
|
*/
|
|
|
|
public static function doesMethodExist(
|
|
|
|
string $fq_classlike_name,
|
|
|
|
string $method_name_lc,
|
|
|
|
StatementsSource $source = null,
|
|
|
|
CodeLocation $code_location = null
|
|
|
|
) {
|
|
|
|
return $method_name_lc === 'magicmethod';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ?bool
|
|
|
|
*/
|
|
|
|
public static function isMethodVisible(
|
|
|
|
StatementsSource $source,
|
|
|
|
string $fq_classlike_name,
|
|
|
|
string $method_name,
|
|
|
|
Context $context = null,
|
|
|
|
CodeLocation $code_location = null
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 getMethodParams(
|
|
|
|
string $fq_classlike_name,
|
|
|
|
string $method_name_lowercase,
|
|
|
|
array $call_args = null,
|
|
|
|
StatementsSource $statements_source = null,
|
|
|
|
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 getMethodReturnType(
|
|
|
|
StatementsSource $source,
|
|
|
|
string $fq_classlike_name,
|
|
|
|
string $method_name,
|
|
|
|
array $call_args,
|
|
|
|
Context $context,
|
2019-03-07 20:56:18 +01:00
|
|
|
CodeLocation $code_location,
|
2019-03-12 17:58:04 +01:00
|
|
|
array $templated_type_parameters = null,
|
|
|
|
string $called_fq_classlike_name = null,
|
|
|
|
string $called_method_name = null
|
2019-03-01 14:57:10 +01:00
|
|
|
) {
|
|
|
|
return Type::getString();
|
|
|
|
}
|
|
|
|
}
|