Skip to content

Commit b29c52b

Browse files
committed
[2.x] Type Callable arguments
1 parent 0a1def7 commit b29c52b

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/PoolInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
interface PoolInterface extends PoolInfoInterface
1111
{
1212
/**
13-
* @param (Closure():T) $callable
14-
* @param array<mixed> $args
13+
* @param (Closure(A ...$args):T) $callable
14+
* @param array<A> $args
1515
*
1616
* @return T
1717
*
1818
* @template T
19+
* @template A
1920
*/
2021
public function run(Closure $callable, array $args = []): mixed;
2122

tests/MockPool.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
namespace ReactParallel\Tests\Contracts;
66

77
use Closure;
8+
use ReactParallel\Contracts\PoolInterface;
89
use WyriHaximus\PoolInfo\PoolInfoInterface;
910

11+
/**
12+
* @phpstan-implements PoolInterface
13+
*/
1014
final class MockPool implements PoolInfoInterface
1115
{
1216
/** @return iterable<string, int> */
@@ -15,14 +19,6 @@ public function info(): iterable
1519
yield from [];
1620
}
1721

18-
/**
19-
* @param (Closure():T) $callable
20-
* @param array<mixed> $args
21-
*
22-
* @return T
23-
*
24-
* @template T
25-
*/
2622
public function run(Closure $callable, array $args = []): mixed
2723
{
2824
return $callable(...$args);

tests/Types.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
declare(strict_types=1);
44

5+
use ReactParallel\Contracts\PoolInterface;
56
use ReactParallel\Tests\Contracts\MockPool;
67

78
use function PHPStan\Testing\assertType;
89

10+
/** @var PoolInterface $pool */
911
$pool = new MockPool();
1012

1113
assertType('bool', $pool->run(static function (): bool {
@@ -15,3 +17,11 @@
1517
assertType('bool|int', $pool->run(static function (): bool|int {
1618
return time() % 2 !== 0 ? true : time();
1719
}));
20+
21+
assertType('bool|int', $pool->run(static function (int $mod): bool|int {
22+
return time() % $mod !== 0 ? true : time();
23+
}, [2]));
24+
25+
assertType('bool|int', $pool->run(static function (int $mod, bool $yolo): bool|int {
26+
return time() % $mod !== 0 ? $yolo : time();
27+
}, [2, true]));

0 commit comments

Comments
 (0)