fix PHPstan

This commit is contained in:
ShockedPlot7560 2024-01-21 12:04:23 +01:00
parent eb9814197b
commit c1e3903934
No known key found for this signature in database
GPG Key ID: 9A66EBFAA7CD3601
4 changed files with 9 additions and 14 deletions

View File

@ -51,9 +51,6 @@ abstract class Event{
//this exception will be caught by the parent event call if all else fails
throw new \RuntimeException("Recursive event call detected (reached max depth of " . self::MAX_EVENT_CALL_DEPTH . " calls)");
}
if($this instanceof AsyncEvent){
throw new \InvalidArgumentException("Cannot call async event synchronously, use callAsync() instead");
}
$timings = Timings::getEventTimings($this);
$timings->startTiming();

View File

@ -38,7 +38,7 @@ class HandlerList{
private array $affectedHandlerCaches = [];
/**
* @phpstan-param class-string<covariant Event> $class
* @phpstan-param class-string<Event|AsyncEvent> $class
*/
public function __construct(
private string $class,

View File

@ -38,7 +38,7 @@ class HandlerListManager{
private array $allLists = [];
/**
* @var RegisteredListenerCache[] event class name => cache
* @phpstan-var array<class-string<Event>, RegisteredListenerCache>
* @phpstan-var array<class-string<Event|AsyncEvent>, RegisteredListenerCache>
*/
private array $handlerCaches = [];
@ -59,7 +59,7 @@ class HandlerListManager{
}
/**
* @phpstan-param \ReflectionClass<Event> $class
* @phpstan-param \ReflectionClass<Event|AsyncEvent> $class
*/
private static function isValidClass(\ReflectionClass $class) : bool{
$tags = Utils::parseDocComment((string) $class->getDocComment());
@ -67,9 +67,9 @@ class HandlerListManager{
}
/**
* @phpstan-param \ReflectionClass<Event> $class
* @phpstan-param \ReflectionClass<Event|AsyncEvent> $class
*
* @phpstan-return \ReflectionClass<Event>|null
* @phpstan-return \ReflectionClass<Event|AsyncEvent>|null
*/
private static function resolveNearestHandleableParent(\ReflectionClass $class) : ?\ReflectionClass{
for($parent = $class->getParentClass(); $parent !== false; $parent = $parent->getParentClass()){
@ -113,7 +113,7 @@ class HandlerListManager{
}
/**
* @phpstan-param class-string<covariant Event> $event
* @phpstan-param class-string<Event|AsyncEvent> $event
*
* @return RegisteredListener[]
*/

View File

@ -692,9 +692,8 @@ class PluginManager{
/**
* @param string $event Class name that extends Event and AsyncEvent
*
* @phpstan-template TEvent of AsyncEvent
* @phpstan-param class-string<TEvent> $event
* @phpstan-param \Closure(TEvent) : Promise<null> $handler
* @phpstan-param class-string<AsyncEvent> $event
* @phpstan-param \Closure(AsyncEvent) : Promise<null> $handler
*
* @throws \ReflectionException
*/
@ -719,8 +718,7 @@ class PluginManager{
/**
* Check if the given handler return type is async-compatible (equal to Promise)
*
* @phpstan-template TEvent of Event&AsyncEvent
* @phpstan-param \Closure(TEvent) : Promise<null> $handler
* @phpstan-param \Closure(AsyncEvent) : Promise<null> $handler
*
* @throws \ReflectionException
*/