-
Notifications
You must be signed in to change notification settings - Fork 504
/
Copy patharray_uintersect.php
94 lines (70 loc) · 2.59 KB
/
array_uintersect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace ArrayUintersect;
use function PHPStan\Testing\assertType;
/**
* @param array<int> $array1
* @param array<string> $array2
* @param array<int, int> $array3
* @param list<string> $list
* @param non-empty-array<int> $nonEmptyArray
* @param array{foo: string, 0?: int} $arrayShape1
* @param array{foo: string, bar?: int} $arrayShape2
*/
function test(array $array1, array $array2, array $array3, array $list, array $nonEmptyArray, array $arrayShape1, array $arrayShape2): void
{
assertType('array<int>', array_uintersect($array1, $array2, static function (mixed $a, mixed $b) {
assertType('int', $a);
assertType('string', $b);
return strcasecmp((string) $a, $b);
}));
assertType('array<string>', array_uintersect($array2, $array1, static function (mixed $a, mixed $b) {
assertType('string', $a);
assertType('int', $b);
return strcasecmp($a, (string) $b);
}));
assertType('array<int>', array_uintersect($array1, $array3, static function (mixed $a, mixed $b) {
assertType('int', $a);
assertType('int', $b);
return $a <=> $b;
}));
assertType('array<int, int>', array_uintersect($array3, $array1, static function (mixed $a, mixed $b) {
assertType('int', $a);
assertType('int', $b);
return $a <=> $b;
}));
assertType('array<int>', array_uintersect($array1, $list, static function (mixed $a, mixed $b) {
assertType('int', $a);
assertType('string', $b);
return strcasecmp((string) $a, $b);
}));
assertType('array<int<0, max>, string>', array_uintersect($list, $array1, static function (mixed $a, mixed $b) {
assertType('string', $a);
assertType('int', $b);
return strcasecmp($a, (string) $b);
}));
assertType('array<int>', array_uintersect($nonEmptyArray, $array1, static function (mixed $a, mixed $b) {
assertType('int', $a);
assertType('int', $b);
return $a <=> $b;
}));
assertType('array<int>', array_uintersect($array1, $nonEmptyArray, static function (mixed $a, mixed $b) {
assertType('int', $a);
assertType('int', $b);
return $a <=> $b;
}));
assertType('array<int>', array_uintersect($array1, $arrayShape1, static function (mixed $a, mixed $b) {
assertType('int', $a);
assertType('int|string', $b);
return $a <=> $b;
}));
assertType("array<0|'foo', int|string>", array_uintersect($arrayShape1, $array1, static function (mixed $a, mixed $b) {
assertType('int|string', $a);
assertType('int', $b);
return $a <=> $b;
}));
assertType("array<'bar'|'foo', int|string>", array_uintersect($arrayShape2, $array1, static function (mixed $a, mixed $b) {
assertType('int|string', $a);
assertType('int', $b);
return $a <=> $b;
}));
}