Skip to content

Commit c368b45

Browse files
committed
allow callbacks in array intersect/diff to return int
See issue 9697
1 parent 2f3d0bb commit c368b45

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

Diff for: stubs/arrayFunctions.stub

+11-11
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function array_is_list(array $value): bool {}
7474
*
7575
* @param array<TK, TV> $one
7676
* @param array<TK, TV> $two
77-
* @param callable(TK, TK): int<-1, 1> $three
77+
* @param callable(TK, TK): int $three
7878
* @return array<TK, TV>
7979
*/
8080
function array_diff_uassoc(
@@ -89,7 +89,7 @@ function array_diff_uassoc(
8989
*
9090
* @param array<TK, TV> $one
9191
* @param array<TK, TV> $two
92-
* @param callable(TK, TK): int<-1, 1> $three
92+
* @param callable(TK, TK): int $three
9393
* @return array<TK, TV>
9494
*/
9595
function array_diff_ukey(
@@ -104,7 +104,7 @@ function array_diff_ukey(
104104
*
105105
* @param array<TK, TV> $one
106106
* @param array<TK, TV> $two
107-
* @param callable(TK, TK): int<-1, 1> $three
107+
* @param callable(TK, TK): int $three
108108
* @return array<TK, TV>
109109
*/
110110
function array_intersect_uassoc(
@@ -119,7 +119,7 @@ function array_intersect_uassoc(
119119
*
120120
* @param array<TK, TV> $one
121121
* @param array<TK, TV> $two
122-
* @param callable(TK, TK): int<-1, 1> $three
122+
* @param callable(TK, TK): int $three
123123
*
124124
* @return array<TK, TV>
125125
*/
@@ -135,7 +135,7 @@ function array_intersect_ukey(
135135
*
136136
* @param array<TK, TV> $one
137137
* @param array<TK, TV> $two
138-
* @param callable(TV, TV): int<-1, 1> $three
138+
* @param callable(TV, TV): int $three
139139
*
140140
* @return array<TK, TV>
141141
*/
@@ -151,8 +151,8 @@ function array_udiff_assoc(
151151
*
152152
* @param array<TK, TV> $one
153153
* @param array<TK, TV> $two
154-
* @param callable(TV, TV): int<-1, 1> $three
155-
* @param callable(TK, TK): int<-1, 1> $four
154+
* @param callable(TV, TV): int $three
155+
* @param callable(TK, TK): int $four
156156
* @return array<TK, TV>
157157
*/
158158
function array_udiff_uassoc(
@@ -168,7 +168,7 @@ function array_udiff_uassoc(
168168
*
169169
* @param array<TK, TV> $one
170170
* @param array<TK, TV> $two
171-
* @param callable(TV, TV): int<-1, 1> $three
171+
* @param callable(TV, TV): int $three
172172
* @return array<TK, TV>
173173
*/
174174
function array_uintersect_assoc(
@@ -183,8 +183,8 @@ function array_uintersect_assoc(
183183
*
184184
* @param array<TK, TV> $one
185185
* @param array<TK, TV> $two
186-
* @param callable(TV, TV): int<-1, 1> $three
187-
* @param callable(TK, TK): int<-1, 1> $four
186+
* @param callable(TV, TV): int $three
187+
* @param callable(TK, TK): int $four
188188
* @return array<TK, TV>
189189
*/
190190
function array_uintersect_uassoc(
@@ -200,7 +200,7 @@ function array_uintersect_uassoc(
200200
*
201201
* @param array<TK, TV> $one
202202
* @param array<TK, TV> $two
203-
* @param callable(TV, TV): int<-1, 1> $three
203+
* @param callable(TV, TV): int $three
204204
* @return array<TK, TV>
205205
*/
206206
function array_uintersect(

Diff for: tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

+22-22
Original file line numberDiff line numberDiff line change
@@ -1721,11 +1721,11 @@ public function testArrayDiffUassoc(): void
17211721
$this->checkExplicitMixed = true;
17221722
$this->analyse([__DIR__ . '/data/array_diff_uassoc.php'], [
17231723
[
1724-
'Parameter #3 $data_comp_func of function array_diff_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1724+
'Parameter #3 $data_comp_func of function array_diff_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int, Closure(int, int): int<-1, 1> given.',
17251725
22,
17261726
],
17271727
[
1728-
'Parameter #3 $data_comp_func of function array_diff_uassoc expects callable(0|1|2|3, 0|1|2|3): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1728+
'Parameter #3 $data_comp_func of function array_diff_uassoc expects callable(0|1|2|3, 0|1|2|3): int, Closure(string, string): int<-1, 1> given.',
17291729
30,
17301730
],
17311731
]);
@@ -1736,11 +1736,11 @@ public function testArrayDiffUkey(): void
17361736
$this->checkExplicitMixed = true;
17371737
$this->analyse([__DIR__ . '/data/array_diff_ukey.php'], [
17381738
[
1739-
'Parameter #3 $key_comp_func of function array_diff_ukey expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1739+
'Parameter #3 $key_comp_func of function array_diff_ukey expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int, Closure(int, int): int<-1, 1> given.',
17401740
22,
17411741
],
17421742
[
1743-
'Parameter #3 $key_comp_func of function array_diff_ukey expects callable(0|1|2|3, 0|1|2|3): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1743+
'Parameter #3 $key_comp_func of function array_diff_ukey expects callable(0|1|2|3, 0|1|2|3): int, Closure(string, string): int<-1, 1> given.',
17441744
30,
17451745
],
17461746
]);
@@ -1751,11 +1751,11 @@ public function testArrayIntersectUassoc(): void
17511751
$this->checkExplicitMixed = true;
17521752
$this->analyse([__DIR__ . '/data/array_intersect_uassoc.php'], [
17531753
[
1754-
'Parameter #3 $key_compare_func of function array_intersect_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1754+
'Parameter #3 $key_compare_func of function array_intersect_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int, Closure(int, int): int<-1, 1> given.',
17551755
22,
17561756
],
17571757
[
1758-
'Parameter #3 $key_compare_func of function array_intersect_uassoc expects callable(0|1|2|3, 0|1|2|3): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1758+
'Parameter #3 $key_compare_func of function array_intersect_uassoc expects callable(0|1|2|3, 0|1|2|3): int, Closure(string, string): int<-1, 1> given.',
17591759
30,
17601760
],
17611761
]);
@@ -1766,11 +1766,11 @@ public function testArrayIntersectUkey(): void
17661766
$this->checkExplicitMixed = true;
17671767
$this->analyse([__DIR__ . '/data/array_intersect_ukey.php'], [
17681768
[
1769-
'Parameter #3 $key_compare_func of function array_intersect_ukey expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1769+
'Parameter #3 $key_compare_func of function array_intersect_ukey expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int, Closure(int, int): int<-1, 1> given.',
17701770
22,
17711771
],
17721772
[
1773-
'Parameter #3 $key_compare_func of function array_intersect_ukey expects callable(0|1|2|3, 0|1|2|3): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1773+
'Parameter #3 $key_compare_func of function array_intersect_ukey expects callable(0|1|2|3, 0|1|2|3): int, Closure(string, string): int<-1, 1> given.',
17741774
30,
17751775
],
17761776
]);
@@ -1781,11 +1781,11 @@ public function testArrayUdiffAssoc(): void
17811781
$this->checkExplicitMixed = true;
17821782
$this->analyse([__DIR__ . '/data/array_udiff_assoc.php'], [
17831783
[
1784-
'Parameter #3 $key_comp_func of function array_udiff_assoc expects callable(1|2, 1|2): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1784+
'Parameter #3 $key_comp_func of function array_udiff_assoc expects callable(1|2, 1|2): int, Closure(string, string): int<-1, 1> given.',
17851785
22,
17861786
],
17871787
[
1788-
'Parameter #3 $key_comp_func of function array_udiff_assoc expects callable(1|2|3|4|5, 1|2|3|4|5): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1788+
'Parameter #3 $key_comp_func of function array_udiff_assoc expects callable(1|2|3|4|5, 1|2|3|4|5): int, Closure(string, string): int<-1, 1> given.',
17891789
30,
17901790
],
17911791
]);
@@ -1796,19 +1796,19 @@ public function testArrayUdiffUasssoc(): void
17961796
$this->checkExplicitMixed = true;
17971797
$this->analyse([__DIR__ . '/data/array_udiff_uassoc.php'], [
17981798
[
1799-
'Parameter #3 $data_comp_func of function array_udiff_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1799+
'Parameter #3 $data_comp_func of function array_udiff_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int, Closure(int, int): int<-1, 1> given.',
18001800
28,
18011801
],
18021802
[
1803-
'Parameter #4 $key_comp_func of function array_udiff_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1803+
'Parameter #4 $key_comp_func of function array_udiff_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int, Closure(int, int): int<-1, 1> given.',
18041804
31,
18051805
],
18061806
[
1807-
'Parameter #3 $data_comp_func of function array_udiff_uassoc expects callable(1|2|3|4|5, 1|2|3|4|5): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1807+
'Parameter #3 $data_comp_func of function array_udiff_uassoc expects callable(1|2|3|4|5, 1|2|3|4|5): int, Closure(string, string): int<-1, 1> given.',
18081808
39,
18091809
],
18101810
[
1811-
'Parameter #4 $key_comp_func of function array_udiff_uassoc expects callable(0|1|2|3, 0|1|2|3): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1811+
'Parameter #4 $key_comp_func of function array_udiff_uassoc expects callable(0|1|2|3, 0|1|2|3): int, Closure(string, string): int<-1, 1> given.',
18121812
42,
18131813
],
18141814
]);
@@ -1819,11 +1819,11 @@ public function testArrayUintersectAssoc(): void
18191819
$this->checkExplicitMixed = true;
18201820
$this->analyse([__DIR__ . '/data/array_uintersect_assoc.php'], [
18211821
[
1822-
'Parameter #3 $data_compare_func of function array_uintersect_assoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1822+
'Parameter #3 $data_compare_func of function array_uintersect_assoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int, Closure(int, int): int<-1, 1> given.',
18231823
22,
18241824
],
18251825
[
1826-
'Parameter #3 $data_compare_func of function array_uintersect_assoc expects callable(1|2|3|4, 1|2|3|4): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1826+
'Parameter #3 $data_compare_func of function array_uintersect_assoc expects callable(1|2|3|4, 1|2|3|4): int, Closure(string, string): int<-1, 1> given.',
18271827
30,
18281828
],
18291829
]);
@@ -1834,19 +1834,19 @@ public function testArrayUintersectUassoc(): void
18341834
$this->checkExplicitMixed = true;
18351835
$this->analyse([__DIR__ . '/data/array_uintersect_uassoc.php'], [
18361836
[
1837-
'Parameter #3 $data_compare_func of function array_uintersect_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1837+
'Parameter #3 $data_compare_func of function array_uintersect_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int, Closure(int, int): int<-1, 1> given.',
18381838
28,
18391839
],
18401840
[
1841-
'Parameter #4 $key_compare_func of function array_uintersect_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1841+
'Parameter #4 $key_compare_func of function array_uintersect_uassoc expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int, Closure(int, int): int<-1, 1> given.',
18421842
31,
18431843
],
18441844
[
1845-
'Parameter #3 $data_compare_func of function array_uintersect_uassoc expects callable(1|2|3|4|5, 1|2|3|4|5): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1845+
'Parameter #3 $data_compare_func of function array_uintersect_uassoc expects callable(1|2|3|4|5, 1|2|3|4|5): int, Closure(string, string): int<-1, 1> given.',
18461846
39,
18471847
],
18481848
[
1849-
'Parameter #4 $key_compare_func of function array_uintersect_uassoc expects callable(0|1|2|3, 0|1|2|3): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1849+
'Parameter #4 $key_compare_func of function array_uintersect_uassoc expects callable(0|1|2|3, 0|1|2|3): int, Closure(string, string): int<-1, 1> given.',
18501850
42,
18511851
],
18521852
]);
@@ -1857,11 +1857,11 @@ public function testArrayUintersect(): void
18571857
$this->checkExplicitMixed = true;
18581858
$this->analyse([__DIR__ . '/data/array_uintersect.php'], [
18591859
[
1860-
'Parameter #3 $data_compare_func of function array_uintersect expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1860+
'Parameter #3 $data_compare_func of function array_uintersect expects callable(\'a\'|\'b\'|\'c\'|\'d\', \'a\'|\'b\'|\'c\'|\'d\'): int, Closure(int, int): int<-1, 1> given.',
18611861
22,
18621862
],
18631863
[
1864-
'Parameter #3 $data_compare_func of function array_uintersect expects callable(1|2|3|4, 1|2|3|4): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1864+
'Parameter #3 $data_compare_func of function array_uintersect expects callable(1|2|3|4, 1|2|3|4): int, Closure(string, string): int<-1, 1> given.',
18651865
30,
18661866
],
18671867
]);

0 commit comments

Comments
 (0)