From d15d1aa2d26e070d6cdefeab0f08daeff9059455 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Thu, 26 Dec 2024 11:50:42 +0100 Subject: [PATCH] [3.x] Add type testing --- etc/qa/phpstan.neon | 4 ++++ src/Runtime.php | 4 ++-- tests/Types.php | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/Types.php diff --git a/etc/qa/phpstan.neon b/etc/qa/phpstan.neon index e618f21..ad3c984 100644 --- a/etc/qa/phpstan.neon +++ b/etc/qa/phpstan.neon @@ -1,5 +1,9 @@ parameters: level: max + ignoreErrors: + - + message: '#Result of method ReactParallel\\Runtime\\Runtime::run\(\) \(void\) is used.#' + path: ../../tests/Types.php ergebnis: noExtends: classesAllowedToBeExtended: diff --git a/src/Runtime.php b/src/Runtime.php index d0846e1..991cb48 100644 --- a/src/Runtime.php +++ b/src/Runtime.php @@ -26,10 +26,10 @@ public function __construct(private EventLoopBridge $eventLoopBridge, string $au } /** - * @param (Closure():?T) $callable + * @param (Closure():T)|(Closure():void) $callable * @param array $args * - * @return ?T + * @return ($callable is (Closure():T) ? T : null) * * @template T */ diff --git a/tests/Types.php b/tests/Types.php new file mode 100644 index 0000000..ecbc388 --- /dev/null +++ b/tests/Types.php @@ -0,0 +1,21 @@ +run(static function (): bool { + return true; +})); + +assertType('bool|int', $pool->run(static function (): bool|int { + return time() % 2 !== 0 ? true : time(); +})); + +assertType('null', $pool->run(static function () { +}));