Skip to content

Commit f3d73a7

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

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

composer.lock

Lines changed: 5 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PoolInterface.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
interface PoolInterface extends PoolInfoInterface
1111
{
1212
/**
13-
* @param (Closure():T) $callable
14-
* @param array<mixed> $args
13+
* @param (Closure():T)|(Closure(A1):T)|(Closure(A1,A2):T)|(Closure(A1,A2,A3):T)|(Closure(A1,A2,A3,A4):T)|(Closure(A1,A2,A3,A4,A5):T) $callable
14+
* @param array{}|array{A1}|array{A1,A2}|array{A1,A2,A3}|array{A1,A2,A3,A4}|array{A1,A2,A3,A4,A5} $args
1515
*
1616
* @return T
1717
*
1818
* @template T
19+
* @template A1 (any number of function arguments, see https://github.com/phpstan/phpstan/issues/8214)
20+
* @template A2
21+
* @template A3
22+
* @template A4
23+
* @template A5
1924
*/
2025
public function run(Closure $callable, array $args = []): mixed;
2126

tests/MockPool.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,20 @@
55
namespace ReactParallel\Tests\Contracts;
66

77
use Closure;
8-
use WyriHaximus\PoolInfo\PoolInfoInterface;
8+
use ReactParallel\Contracts\PoolInterface;
99

10-
final class MockPool implements PoolInfoInterface
10+
final class MockPool implements PoolInterface
1111
{
12-
/** @return iterable<string, int> */
12+
/**
13+
* {@inheritDoc}
14+
*/
1315
public function info(): iterable
1416
{
1517
yield from [];
1618
}
1719

1820
/**
19-
* @param (Closure():T) $callable
20-
* @param array<mixed> $args
21-
*
22-
* @return T
23-
*
24-
* @template T
21+
* {@inheritDoc}
2522
*/
2623
public function run(Closure $callable, array $args = []): mixed
2724
{

tests/Types.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@
88

99
$pool = new MockPool();
1010

11-
assertType('bool', $pool->run(static function (): bool {
11+
assertType('true', $pool->run(static function (): bool {
1212
return true;
1313
}));
1414

15-
assertType('bool|int', $pool->run(static function (): bool|int {
15+
assertType('int<1, max>|true', $pool->run(static function (): bool|int {
1616
return time() % 2 !== 0 ? true : time();
1717
}));
18+
19+
assertType('int<1, max>|true', $pool->run(static function (int $mod): bool|int {
20+
return time() % $mod !== 0 ? true : time();
21+
}, [2]));
22+
23+
assertType('bool|int<1, max>', $pool->run(static function (int $mod, bool $yolo): bool|int {
24+
return time() % $mod !== 0 ? $yolo : time();
25+
}, [2, (time() % 13 !== 0)]));
26+
27+
assertType('bool|non-empty-string', $pool->run(static function (int $mod, bool $yolo, string $oloy): bool|string {
28+
return time() % $mod !== 0 ? $yolo : $oloy;
29+
}, [2, (time() % 13 !== 0), bin2hex(random_bytes(13))]));

0 commit comments

Comments
 (0)