Skip to content

Commit 416bdb3

Browse files
mad-brillerondrejmirtes
authored andcommitted
Added stub files and tests for:
array_diff_uassoc array_diff_ukey array_intersect_uassoc array_intersect_ukey array_udiff_assoc array_udiff_uassoc array_uintersect_assoc array_uintersect_uassoc array_uintersect
1 parent 031f34e commit 416bdb3

11 files changed

+613
-0
lines changed

stubs/arrayFunctions.stub

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,144 @@ function array_udiff(
7575
* @return ($value is __always-list ? true : false)
7676
*/
7777
function array_is_list(array $value): bool {}
78+
79+
/**
80+
* @template TK of mixed
81+
* @template TV of mixed
82+
*
83+
* @param array<TK, TV> $one
84+
* @param array<TK, TV> $two
85+
* @param callable(TK, TK): int<-1, 1> $three
86+
* @return array<TK, TV>
87+
*/
88+
function array_diff_uassoc(
89+
array $one,
90+
array $two,
91+
callable $three
92+
): array {}
93+
94+
/**
95+
* @template TK of mixed
96+
* @template TV of mixed
97+
*
98+
* @param array<TK, TV> $one
99+
* @param array<TK, TV> $two
100+
* @param callable(TK, TK): int<-1, 1> $three
101+
* @return array<TK, TV>
102+
*/
103+
function array_diff_ukey(
104+
array $one,
105+
array $two,
106+
callable $three
107+
): array {}
108+
109+
/**
110+
* @template TK of mixed
111+
* @template TV of mixed
112+
*
113+
* @param array<TK, TV> $one
114+
* @param array<TK, TV> $two
115+
* @param callable(TK, TK): int<-1, 1> $three
116+
* @return array<TK, TV>
117+
*/
118+
function array_intersect_uassoc(
119+
array $one,
120+
array $two,
121+
callable $three
122+
): array {}
123+
124+
/**
125+
* @template TK of mixed
126+
* @template TV of mixed
127+
*
128+
* @param array<TK, TV> $one
129+
* @param array<TK, TV> $two
130+
* @param callable(TK, TK): int<-1, 1> $three
131+
*
132+
* @return array<TK, TV>
133+
*/
134+
function array_intersect_ukey(
135+
array $one,
136+
array $two,
137+
callable $three
138+
): array {}
139+
140+
/**
141+
* @template TK of mixed
142+
* @template TV of mixed
143+
*
144+
* @param array<TK, TV> $one
145+
* @param array<TK, TV> $two
146+
* @param callable(TV, TV): int<-1, 1> $three
147+
*
148+
* @return array<TK, TV>
149+
*/
150+
function array_udiff_assoc(
151+
array $one,
152+
array $two,
153+
callable $three
154+
): array {}
155+
156+
/**
157+
* @template TK of mixed
158+
* @template TV of mixed
159+
*
160+
* @param array<TK, TV> $one
161+
* @param array<TK, TV> $two
162+
* @param callable(TV, TV): int<-1, 1> $three
163+
* @param callable(TK, TK): int<-1, 1> $four
164+
* @return array<TK, TV>
165+
*/
166+
function array_udiff_uassoc(
167+
array $one,
168+
array $two,
169+
callable $three,
170+
callable $four
171+
): array {}
172+
173+
/**
174+
* @template TK of mixed
175+
* @template TV of mixed
176+
*
177+
* @param array<TK, TV> $one
178+
* @param array<TK, TV> $two
179+
* @param callable(TV, TV): int<-1, 1> $three
180+
* @return array<TK, TV>
181+
*/
182+
function array_uintersect_assoc(
183+
array $one,
184+
array $two,
185+
callable $three,
186+
): array {}
187+
188+
/**
189+
* @template TK of mixed
190+
* @template TV of mixed
191+
*
192+
* @param array<TK, TV> $one
193+
* @param array<TK, TV> $two
194+
* @param callable(TV, TV): int<-1, 1> $three
195+
* @param callable(TK, TK): int<-1, 1> $four
196+
* @return array<TK, TV>
197+
*/
198+
function array_uintersect_uassoc(
199+
array $one,
200+
array $two,
201+
callable $three,
202+
callable $four
203+
): array {}
204+
205+
/**
206+
* @template TK of mixed
207+
* @template TV of mixed
208+
*
209+
* @param array<TK, TV> $one
210+
* @param array<TK, TV> $two
211+
* @param callable(TV, TV): int<-1, 1> $three
212+
* @return array<TK, TV>
213+
*/
214+
function array_uintersect(
215+
array $one,
216+
array $two,
217+
callable $three,
218+
): array {}

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,157 @@ public function testCountArrayShift(): void
18391839
$this->analyse([__DIR__ . '/data/count-array-shift.php'], $errors);
18401840
}
18411841

1842+
public function testArrayDiffUassoc(): void
1843+
{
1844+
$this->checkExplicitMixed = true;
1845+
$this->analyse([__DIR__ . '/data/array_diff_uassoc.php'], [
1846+
[
1847+
'Parameter #3 $data_comp_func of function array_diff_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1848+
22,
1849+
],
1850+
[
1851+
'Parameter #3 $data_comp_func of function array_diff_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1852+
30,
1853+
],
1854+
]);
1855+
}
1856+
1857+
public function testArrayDiffUkey(): void
1858+
{
1859+
$this->checkExplicitMixed = true;
1860+
$this->analyse([__DIR__ . '/data/array_diff_ukey.php'], [
1861+
[
1862+
'Parameter #3 $key_comp_func of function array_diff_ukey expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1863+
22,
1864+
],
1865+
[
1866+
'Parameter #3 $key_comp_func of function array_diff_ukey expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1867+
30,
1868+
],
1869+
]);
1870+
}
1871+
1872+
public function testArrayIntersectUassoc(): void
1873+
{
1874+
$this->checkExplicitMixed = true;
1875+
$this->analyse([__DIR__ . '/data/array_intersect_uassoc.php'], [
1876+
[
1877+
'Parameter #3 $key_compare_func of function array_intersect_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1878+
22,
1879+
],
1880+
[
1881+
'Parameter #3 $key_compare_func of function array_intersect_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1882+
30,
1883+
],
1884+
]);
1885+
}
1886+
1887+
public function testArrayIntersectUkey(): void
1888+
{
1889+
$this->checkExplicitMixed = true;
1890+
$this->analyse([__DIR__ . '/data/array_intersect_ukey.php'], [
1891+
[
1892+
'Parameter #3 $key_compare_func of function array_intersect_ukey expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1893+
22,
1894+
],
1895+
[
1896+
'Parameter #3 $key_compare_func of function array_intersect_ukey expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1897+
30,
1898+
],
1899+
]);
1900+
}
1901+
1902+
public function testArrayUdiffAssoc(): void
1903+
{
1904+
$this->checkExplicitMixed = true;
1905+
$this->analyse([__DIR__ . '/data/array_udiff_assoc.php'], [
1906+
[
1907+
'Parameter #3 $key_comp_func of function array_udiff_assoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1908+
22,
1909+
],
1910+
[
1911+
'Parameter #3 $key_comp_func of function array_udiff_assoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1912+
30,
1913+
],
1914+
]);
1915+
}
1916+
1917+
public function testArrayUdiffUsssoc(): void
1918+
{
1919+
$this->checkExplicitMixed = true;
1920+
$this->analyse([__DIR__ . '/data/array_udiff_uassoc.php'], [
1921+
[
1922+
'Parameter #3 $data_comp_func of function array_udiff_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1923+
28,
1924+
],
1925+
[
1926+
'Parameter #4 $key_comp_func of function array_udiff_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1927+
31,
1928+
],
1929+
[
1930+
'Parameter #3 $data_comp_func of function array_udiff_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1931+
39,
1932+
],
1933+
[
1934+
'Parameter #4 $key_comp_func of function array_udiff_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1935+
42,
1936+
],
1937+
]);
1938+
}
1939+
1940+
public function testArrayUintersectAssoc(): void
1941+
{
1942+
$this->checkExplicitMixed = true;
1943+
$this->analyse([__DIR__ . '/data/array_uintersect_assoc.php'], [
1944+
[
1945+
'Parameter #3 $data_compare_func of function array_uintersect_assoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1946+
22,
1947+
],
1948+
[
1949+
'Parameter #3 $data_compare_func of function array_uintersect_assoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1950+
30,
1951+
],
1952+
]);
1953+
}
1954+
1955+
public function testArrayUintersectUassoc(): void
1956+
{
1957+
$this->checkExplicitMixed = true;
1958+
$this->analyse([__DIR__ . '/data/array_uintersect_uassoc.php'], [
1959+
[
1960+
'Parameter #3 $data_compare_func of function array_uintersect_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1961+
28,
1962+
],
1963+
[
1964+
'Parameter #4 $key_compare_func of function array_uintersect_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1965+
31,
1966+
],
1967+
[
1968+
'Parameter #3 $data_compare_func of function array_uintersect_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1969+
39,
1970+
],
1971+
[
1972+
'Parameter #4 $key_compare_func of function array_uintersect_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1973+
42,
1974+
],
1975+
]);
1976+
}
1977+
1978+
public function testArrayUintersect(): void
1979+
{
1980+
$this->checkExplicitMixed = true;
1981+
$this->analyse([__DIR__ . '/data/array_uintersect.php'], [
1982+
[
1983+
'Parameter #3 $data_compare_func of function array_uintersect expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1984+
22,
1985+
],
1986+
[
1987+
'Parameter #3 $data_compare_func of function array_uintersect expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1988+
30,
1989+
],
1990+
]);
1991+
}
1992+
18421993
public function testNoNamedArguments(): void
18431994
{
18441995
if (PHP_VERSION_ID < 80000) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
array_diff_uassoc(
4+
['a' => 1, 'b' => 2],
5+
['c' => 1, 'd' => 2],
6+
static function (string $a, string $b): int {
7+
return $a <=> $b;
8+
}
9+
);
10+
11+
array_diff_uassoc(
12+
[1, 2, 3],
13+
[1, 2, 4, 5],
14+
static function (int $a, int $b): int {
15+
return $a <=> $b;
16+
}
17+
);
18+
19+
array_diff_uassoc(
20+
['a' => 1, 'b' => 2],
21+
['c' => 1, 'd' => 2],
22+
static function (int $a, int $b): int {
23+
return $a <=> $b;
24+
}
25+
);
26+
27+
array_diff_uassoc(
28+
[1, 2, 3],
29+
[1, 2, 4, 5],
30+
static function (string $a, string $b): int {
31+
return $a <=> $b;
32+
}
33+
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
array_diff_ukey(
4+
['a' => 1, 'b' => 2],
5+
['c' => 1, 'd' => 2],
6+
static function (string $a, string $b): int {
7+
return $a <=> $b;
8+
}
9+
);
10+
11+
array_diff_ukey(
12+
[1, 2, 3],
13+
[1, 2, 4, 5],
14+
static function (int $a, int $b): int {
15+
return $a <=> $b;
16+
}
17+
);
18+
19+
array_diff_ukey(
20+
['a' => 1, 'b' => 2],
21+
['c' => 1, 'd' => 2],
22+
static function (int $a, int $b): int {
23+
return $a <=> $b;
24+
}
25+
);
26+
27+
array_diff_ukey(
28+
[1, 2, 3],
29+
[1, 2, 4, 5],
30+
static function (string $a, string $b): int {
31+
return $a <=> $b;
32+
}
33+
);

0 commit comments

Comments
 (0)