Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2799c24

Browse files
authored
Add callback types for array_uintersect etc.
1 parent 031f34e commit 2799c24

14 files changed

+859
-9
lines changed

‎src/Type/TypehintHelper.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,11 @@ public static function decideType(
201201
}
202202

203203
if (
204-
(!$phpDocType instanceof NeverType || ($type instanceof MixedType && !$type->isExplicitMixed()))
205-
&& $type->isSuperTypeOf(TemplateTypeHelper::resolveToBounds($phpDocType))->yes()
204+
($type->isCallable()->yes() && $phpDocType->isCallable()->yes())
205+
|| (
206+
(!$phpDocType instanceof NeverType || ($type instanceof MixedType && !$type->isExplicitMixed()))
207+
&& $type->isSuperTypeOf(TemplateTypeHelper::resolveToBounds($phpDocType))->yes()
208+
)
206209
) {
207210
$resultType = $phpDocType;
208211
} else {

‎stubs/arrayFunctions.stub‎

Lines changed: 148 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,163 @@ function uksort(array &$array, callable $callback): bool
5858
}
5959

6060
/**
61-
* @template T of mixed
61+
* @template TV of mixed
62+
* @template TK of mixed
6263
*
63-
* @param array<T> $one
64-
* @param array<T> $two
65-
* @param callable(T, T): int $three
64+
* @param array<TK, TV> $one
65+
* @param array<TK, TV> $two
66+
* @param callable(TV, TV): int $three
67+
* @return array<TK, TV>
6668
*/
6769
function array_udiff(
6870
array $one,
6971
array $two,
7072
callable $three
71-
): int {}
73+
): array {}
7274

7375
/**
7476
* @param array<array-key, mixed> $value
7577
* @return ($value is __always-list ? true : false)
7678
*/
7779
function array_is_list(array $value): bool {}
80+
81+
/**
82+
* @template TK of array-key
83+
* @template TV of mixed
84+
*
85+
* @param array<TK, TV> $one
86+
* @param array<TK, TV> $two
87+
* @param callable(TK, TK): int $three
88+
* @return array<TK, TV>
89+
*/
90+
function array_diff_uassoc(
91+
array $one,
92+
array $two,
93+
callable $three
94+
): array {}
95+
96+
/**
97+
* @template TK of array-key
98+
* @template TV of mixed
99+
*
100+
* @param array<TK, TV> $one
101+
* @param array<TK, TV> $two
102+
* @param callable(TK, TK): int $three
103+
* @return array<TK, TV>
104+
*/
105+
function array_diff_ukey(
106+
array $one,
107+
array $two,
108+
callable $three
109+
): array {}
110+
111+
/**
112+
* @template TK of array-key
113+
* @template TV of mixed
114+
*
115+
* @param array<TK, TV> $one
116+
* @param array<TK, TV> $two
117+
* @param callable(TK, TK): int $three
118+
* @return array<TK, TV>
119+
*/
120+
function array_intersect_uassoc(
121+
array $one,
122+
array $two,
123+
callable $three
124+
): array {}
125+
126+
/**
127+
* @template TK of array-key
128+
* @template TV of mixed
129+
*
130+
* @param array<TK, TV> $one
131+
* @param array<TK, TV> $two
132+
* @param callable(TK, TK): int $three
133+
*
134+
* @return array<TK, TV>
135+
*/
136+
function array_intersect_ukey(
137+
array $one,
138+
array $two,
139+
callable $three
140+
): array {}
141+
142+
/**
143+
* @template TK of array-key
144+
* @template TV of mixed
145+
*
146+
* @param array<TK, TV> $one
147+
* @param array<TK, TV> $two
148+
* @param callable(TV, TV): int $three
149+
*
150+
* @return array<TK, TV>
151+
*/
152+
function array_udiff_assoc(
153+
array $one,
154+
array $two,
155+
callable $three
156+
): array {}
157+
158+
/**
159+
* @template TK of array-key
160+
* @template TV of mixed
161+
*
162+
* @param array<TK, TV> $one
163+
* @param array<TK, TV> $two
164+
* @param callable(TV, TV): int $three
165+
* @param callable(TK, TK): int $four
166+
* @return array<TK, TV>
167+
*/
168+
function array_udiff_uassoc(
169+
array $one,
170+
array $two,
171+
callable $three,
172+
callable $four
173+
): array {}
174+
175+
/**
176+
* @template TK of array-key
177+
* @template TV of mixed
178+
*
179+
* @param array<TK, TV> $one
180+
* @param array<TK, TV> $two
181+
* @param callable(TV, TV): int $three
182+
* @return array<TK, TV>
183+
*/
184+
function array_uintersect_assoc(
185+
array $one,
186+
array $two,
187+
callable $three,
188+
): array {}
189+
190+
/**
191+
* @template TK of array-key
192+
* @template TV of mixed
193+
*
194+
* @param array<TK, TV> $one
195+
* @param array<TK, TV> $two
196+
* @param callable(TV, TV): int $three
197+
* @param callable(TK, TK): int $four
198+
* @return array<TK, TV>
199+
*/
200+
function array_uintersect_uassoc(
201+
array $one,
202+
array $two,
203+
callable $three,
204+
callable $four
205+
): array {}
206+
207+
/**
208+
* @template TK of array-key
209+
* @template TV of mixed
210+
*
211+
* @param array<TK, TV> $one
212+
* @param array<TK, TV> $two
213+
* @param callable(TV, TV): int $three
214+
* @return array<TK, TV>
215+
*/
216+
function array_uintersect(
217+
array $one,
218+
array $two,
219+
callable $three,
220+
): array {}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace ArrayDiffIntersectCallbacks;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
array_diff_uassoc(
8+
[1, 2],
9+
[3, 4],
10+
static function ($a, $b) {
11+
assertType('0|1', $a);
12+
assertType('0|1', $b);
13+
14+
return 0;
15+
},
16+
);
17+
18+
array_diff_ukey(
19+
[1, 2],
20+
[3, 4],
21+
static function ($a, $b) {
22+
assertType('0|1', $a);
23+
assertType('0|1', $b);
24+
25+
return 0;
26+
},
27+
);
28+
29+
array_intersect_uassoc(
30+
[1, 2],
31+
[3, 4],
32+
static function ($a, $b) {
33+
assertType('0|1', $a);
34+
assertType('0|1', $b);
35+
36+
return 0;
37+
},
38+
);
39+
40+
array_intersect_ukey(
41+
[1, 2],
42+
[3, 4],
43+
static function ($a, $b) {
44+
assertType('0|1', $a);
45+
assertType('0|1', $b);
46+
47+
return 0;
48+
},
49+
);
50+
51+
array_udiff(
52+
[1, 2],
53+
[3, 4],
54+
static function ($a, $b) {
55+
assertType('1|2|3|4', $a);
56+
assertType('1|2|3|4', $b);
57+
58+
return 0;
59+
},
60+
);
61+
62+
array_udiff_assoc(
63+
[1, 2],
64+
[3, 4],
65+
static function ($a, $b) {
66+
assertType('1|2|3|4', $a);
67+
assertType('1|2|3|4', $b);
68+
69+
return 0;
70+
},
71+
);
72+
73+
array_udiff_uassoc(
74+
[1, 2],
75+
[3, 4],
76+
static function ($a, $b) {
77+
assertType('1|2|3|4', $a);
78+
assertType('1|2|3|4', $b);
79+
80+
return 0;
81+
},
82+
static function ($a, $b) {
83+
assertType('0|1', $a);
84+
assertType('0|1', $b);
85+
86+
return 0;
87+
},
88+
);
89+
90+
array_uintersect(
91+
[1, 2],
92+
[3, 4],
93+
static function ($a, $b) {
94+
assertType('1|2|3|4', $a);
95+
assertType('1|2|3|4', $b);
96+
97+
return 0;
98+
},
99+
);
100+
101+
array_uintersect_assoc(
102+
[1, 2],
103+
[3, 4],
104+
static function ($a, $b) {
105+
assertType('1|2|3|4', $a);
106+
assertType('1|2|3|4', $b);
107+
108+
return 0;
109+
},
110+
);
111+
112+
array_uintersect_uassoc(
113+
[1, 2],
114+
[3, 4],
115+
static function ($a, $b) {
116+
assertType('1|2|3|4', $a);
117+
assertType('1|2|3|4', $b);
118+
119+
return 0;
120+
},
121+
static function ($a, $b) {
122+
assertType('0|1', $a);
123+
assertType('0|1', $b);
124+
125+
return 0;
126+
},
127+
);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /