1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00
psalm/tests/Config/Plugin/Hook/FooMethodProvider.php

61 lines
1.9 KiB
PHP
Raw Normal View History

<?php
2019-05-10 00:58:30 +02:00
namespace Psalm\Test\Config\Plugin\Hook;
use Psalm\Plugin\EventHandler\Event\MethodExistenceProviderEvent;
use Psalm\Plugin\EventHandler\Event\MethodParamsProviderEvent;
use Psalm\Plugin\EventHandler\Event\MethodReturnTypeProviderEvent;
2021-06-08 04:55:21 +02:00
use Psalm\Plugin\EventHandler\MethodExistenceProviderInterface;
use Psalm\Plugin\EventHandler\MethodParamsProviderInterface;
use Psalm\Plugin\EventHandler\MethodReturnTypeProviderInterface;
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-03 20:11:20 +01:00
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Union;
class FooMethodProvider implements
MethodExistenceProviderInterface,
MethodParamsProviderInterface,
MethodReturnTypeProviderInterface
{
/**
* @return array<string>
*/
public static function getClassLikeNames() : array
{
return ['Ns\Foo'];
}
public static function doesMethodExist(MethodExistenceProviderEvent $event): ?bool
{
$method_name_lowercase = $event->getMethodNameLowercase();
if ($method_name_lowercase === 'magicmethod' || $method_name_lowercase === 'magicmethod2') {
return true;
}
return null;
}
/**
2021-12-04 03:37:19 +01:00
* @return ?array<int, FunctionLikeParameter>
*/
public static function getMethodParams(MethodParamsProviderEvent $event): ?array
{
$method_name_lowercase = $event->getMethodNameLowercase();
if ($method_name_lowercase === 'magicmethod' || $method_name_lowercase === 'magicmethod2') {
2021-12-03 20:11:20 +01:00
return [new FunctionLikeParameter('first', false, Type::getString())];
}
return null;
}
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Type\Union
{
$method_name_lowercase = $event->getMethodNameLowercase();
if ($method_name_lowercase === 'magicmethod') {
return Type::getString();
} else {
2021-12-03 20:11:20 +01:00
return new Union([new TNamedObject('NS\\Foo2')]);
}
}
}