Skip to content

Commit ba154ee

Browse files
committed
Add generic typings to array_uintersect
1 parent efdd51e commit ba154ee

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

stubs/arrayFunctions.stub

+12
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ function array_udiff(
7070
callable $three
7171
): int {}
7272

73+
/**
74+
* @template T
75+
* @param array<T> $one
76+
* @param array<T> $two
77+
* @param callable(T, T): int $three
78+
*/
79+
function array_uintersect(
80+
array $one,
81+
array $two,
82+
callable $three
83+
): int {}
84+
7385
/**
7486
* @param array<array-key, mixed> $value
7587
* @return ($value is list ? true : false)

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,32 @@ public function testArrayUdiffCallback(): void
663663
]);
664664
}
665665

666+
public function testArrayUintersectCallback(): void
667+
{
668+
$this->analyse([__DIR__ . '/data/array_uintersect.php'], [
669+
[
670+
'Parameter #3 $data_compare_func of function array_uintersect expects callable(1|2|3|4|5|6, 1|2|3|4|5|6): int, Closure(string, string): string given.',
671+
6,
672+
],
673+
[
674+
'Parameter #3 $data_compare_func of function array_uintersect expects callable(1|2|3|4|5|6, 1|2|3|4|5|6): int, Closure(int, int): (literal-string&lowercase-string&non-falsy-string&numeric-string&uppercase-string) given.',
675+
14,
676+
],
677+
[
678+
'Parameter #1 $arr1 of function array_uintersect expects array<string>, null given.',
679+
20,
680+
],
681+
[
682+
'Parameter #2 $arr2 of function array_uintersect expects array<string>, null given.',
683+
21,
684+
],
685+
[
686+
'Parameter #3 $data_compare_func of function array_uintersect expects callable(string, string): int, Closure(string, int): non-empty-string given.',
687+
22,
688+
],
689+
]);
690+
}
691+
666692
public function testPregReplaceCallback(): void
667693
{
668694
$this->analyse([__DIR__ . '/data/preg_replace_callback.php'], [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types = 1);
2+
3+
array_uintersect(
4+
[1,2,3],
5+
[4,5,6],
6+
function(string $a, string $b): string {
7+
return $a . $b;
8+
},
9+
);
10+
11+
array_uintersect(
12+
[1,2,3],
13+
[4,5,6],
14+
function(int $a, int $b): string {
15+
return $a . $b;
16+
},
17+
);
18+
19+
array_uintersect(
20+
null,
21+
null,
22+
function(string $a, int $b): string {
23+
return $a . $b;
24+
},
25+
);
26+
27+
array_uintersect(
28+
[25,26],
29+
[26,27],
30+
static function(int $a, int $b): int {
31+
return $a <=> $b;
32+
},
33+
);
34+
35+
array_uintersect(
36+
["25","26"],
37+
["26","27"],
38+
'strcasecmp',
39+
);

0 commit comments

Comments
 (0)