Skip to content

Commit 3046fa9

Browse files
schlndhondrejmirtes
authored andcommitted
allow callbacks in array intersect/diff to return int
See issue 9697
1 parent 7b6d8d4 commit 3046fa9

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

stubs/arrayFunctions.stub

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function array_is_list(array $value): bool {}
8282
*
8383
* @param array<TK, TV> $one
8484
* @param array<TK, TV> $two
85-
* @param callable(TK, TK): int<-1, 1> $three
85+
* @param callable(TK, TK): int $three
8686
* @return array<TK, TV>
8787
*/
8888
function array_diff_uassoc(
@@ -97,7 +97,7 @@ function array_diff_uassoc(
9797
*
9898
* @param array<TK, TV> $one
9999
* @param array<TK, TV> $two
100-
* @param callable(TK, TK): int<-1, 1> $three
100+
* @param callable(TK, TK): int $three
101101
* @return array<TK, TV>
102102
*/
103103
function array_diff_ukey(
@@ -112,7 +112,7 @@ function array_diff_ukey(
112112
*
113113
* @param array<TK, TV> $one
114114
* @param array<TK, TV> $two
115-
* @param callable(TK, TK): int<-1, 1> $three
115+
* @param callable(TK, TK): int $three
116116
* @return array<TK, TV>
117117
*/
118118
function array_intersect_uassoc(
@@ -127,7 +127,7 @@ function array_intersect_uassoc(
127127
*
128128
* @param array<TK, TV> $one
129129
* @param array<TK, TV> $two
130-
* @param callable(TK, TK): int<-1, 1> $three
130+
* @param callable(TK, TK): int $three
131131
*
132132
* @return array<TK, TV>
133133
*/
@@ -143,7 +143,7 @@ function array_intersect_ukey(
143143
*
144144
* @param array<TK, TV> $one
145145
* @param array<TK, TV> $two
146-
* @param callable(TV, TV): int<-1, 1> $three
146+
* @param callable(TV, TV): int $three
147147
*
148148
* @return array<TK, TV>
149149
*/
@@ -159,8 +159,8 @@ function array_udiff_assoc(
159159
*
160160
* @param array<TK, TV> $one
161161
* @param array<TK, TV> $two
162-
* @param callable(TV, TV): int<-1, 1> $three
163-
* @param callable(TK, TK): int<-1, 1> $four
162+
* @param callable(TV, TV): int $three
163+
* @param callable(TK, TK): int $four
164164
* @return array<TK, TV>
165165
*/
166166
function array_udiff_uassoc(
@@ -176,7 +176,7 @@ function array_udiff_uassoc(
176176
*
177177
* @param array<TK, TV> $one
178178
* @param array<TK, TV> $two
179-
* @param callable(TV, TV): int<-1, 1> $three
179+
* @param callable(TV, TV): int $three
180180
* @return array<TK, TV>
181181
*/
182182
function array_uintersect_assoc(
@@ -191,8 +191,8 @@ function array_uintersect_assoc(
191191
*
192192
* @param array<TK, TV> $one
193193
* @param array<TK, TV> $two
194-
* @param callable(TV, TV): int<-1, 1> $three
195-
* @param callable(TK, TK): int<-1, 1> $four
194+
* @param callable(TV, TV): int $three
195+
* @param callable(TK, TK): int $four
196196
* @return array<TK, TV>
197197
*/
198198
function array_uintersect_uassoc(
@@ -208,7 +208,7 @@ function array_uintersect_uassoc(
208208
*
209209
* @param array<TK, TV> $one
210210
* @param array<TK, TV> $two
211-
* @param callable(TV, TV): int<-1, 1> $three
211+
* @param callable(TV, TV): int $three
212212
* @return array<TK, TV>
213213
*/
214214
function array_uintersect(

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,11 +1844,11 @@ public function testArrayDiffUassoc(): void
18441844
$this->checkExplicitMixed = true;
18451845
$this->analyse([__DIR__ . '/data/array_diff_uassoc.php'], [
18461846
[
1847-
'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.',
1847+
'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.',
18481848
22,
18491849
],
18501850
[
1851-
'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.',
1851+
'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.',
18521852
30,
18531853
],
18541854
]);
@@ -1859,11 +1859,11 @@ public function testArrayDiffUkey(): void
18591859
$this->checkExplicitMixed = true;
18601860
$this->analyse([__DIR__ . '/data/array_diff_ukey.php'], [
18611861
[
1862-
'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.',
1862+
'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.',
18631863
22,
18641864
],
18651865
[
1866-
'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.',
1866+
'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.',
18671867
30,
18681868
],
18691869
]);
@@ -1874,11 +1874,11 @@ public function testArrayIntersectUassoc(): void
18741874
$this->checkExplicitMixed = true;
18751875
$this->analyse([__DIR__ . '/data/array_intersect_uassoc.php'], [
18761876
[
1877-
'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.',
1877+
'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.',
18781878
22,
18791879
],
18801880
[
1881-
'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.',
1881+
'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.',
18821882
30,
18831883
],
18841884
]);
@@ -1889,11 +1889,11 @@ public function testArrayIntersectUkey(): void
18891889
$this->checkExplicitMixed = true;
18901890
$this->analyse([__DIR__ . '/data/array_intersect_ukey.php'], [
18911891
[
1892-
'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.',
1892+
'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.',
18931893
22,
18941894
],
18951895
[
1896-
'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.',
1896+
'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.',
18971897
30,
18981898
],
18991899
]);
@@ -1904,11 +1904,11 @@ public function testArrayUdiffAssoc(): void
19041904
$this->checkExplicitMixed = true;
19051905
$this->analyse([__DIR__ . '/data/array_udiff_assoc.php'], [
19061906
[
1907-
'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.',
1907+
'Parameter #3 $key_comp_func of function array_udiff_assoc expects callable(1|2, 1|2): int, Closure(string, string): int<-1, 1> given.',
19081908
22,
19091909
],
19101910
[
1911-
'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.',
1911+
'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.',
19121912
30,
19131913
],
19141914
]);
@@ -1919,19 +1919,19 @@ public function testArrayUdiffUasssoc(): void
19191919
$this->checkExplicitMixed = true;
19201920
$this->analyse([__DIR__ . '/data/array_udiff_uassoc.php'], [
19211921
[
1922-
'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.',
1922+
'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.',
19231923
28,
19241924
],
19251925
[
1926-
'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.',
1926+
'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.',
19271927
31,
19281928
],
19291929
[
1930-
'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.',
1930+
'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.',
19311931
39,
19321932
],
19331933
[
1934-
'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.',
1934+
'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.',
19351935
42,
19361936
],
19371937
]);
@@ -1942,11 +1942,11 @@ public function testArrayUintersectAssoc(): void
19421942
$this->checkExplicitMixed = true;
19431943
$this->analyse([__DIR__ . '/data/array_uintersect_assoc.php'], [
19441944
[
1945-
'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.',
1945+
'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.',
19461946
22,
19471947
],
19481948
[
1949-
'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.',
1949+
'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.',
19501950
30,
19511951
],
19521952
]);
@@ -1957,19 +1957,19 @@ public function testArrayUintersectUassoc(): void
19571957
$this->checkExplicitMixed = true;
19581958
$this->analyse([__DIR__ . '/data/array_uintersect_uassoc.php'], [
19591959
[
1960-
'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.',
1960+
'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.',
19611961
28,
19621962
],
19631963
[
1964-
'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.',
1964+
'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.',
19651965
31,
19661966
],
19671967
[
1968-
'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.',
1968+
'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.',
19691969
39,
19701970
],
19711971
[
1972-
'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.',
1972+
'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.',
19731973
42,
19741974
],
19751975
]);
@@ -1980,11 +1980,11 @@ public function testArrayUintersect(): void
19801980
$this->checkExplicitMixed = true;
19811981
$this->analyse([__DIR__ . '/data/array_uintersect.php'], [
19821982
[
1983-
'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.',
1983+
'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.',
19841984
22,
19851985
],
19861986
[
1987-
'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.',
1987+
'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.',
19881988
30,
19891989
],
19901990
]);

0 commit comments

Comments
 (0)