Skip to content

Commit 9b634cf

Browse files
mad-brillerschlndh
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 475a18c commit 9b634cf

11 files changed

+613
-0
lines changed

stubs/arrayFunctions.stub

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

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

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

1719+
public function testArrayDiffUassoc(): void
1720+
{
1721+
$this->checkExplicitMixed = true;
1722+
$this->analyse([__DIR__ . '/data/array_diff_uassoc.php'], [
1723+
[
1724+
'Parameter #3 $data_comp_func of function array_diff_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1725+
22,
1726+
],
1727+
[
1728+
'Parameter #3 $data_comp_func of function array_diff_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1729+
30,
1730+
],
1731+
]);
1732+
}
1733+
1734+
public function testArrayDiffUkey(): void
1735+
{
1736+
$this->checkExplicitMixed = true;
1737+
$this->analyse([__DIR__ . '/data/array_diff_ukey.php'], [
1738+
[
1739+
'Parameter #3 $key_comp_func of function array_diff_ukey expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1740+
22,
1741+
],
1742+
[
1743+
'Parameter #3 $key_comp_func of function array_diff_ukey expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1744+
30,
1745+
],
1746+
]);
1747+
}
1748+
1749+
public function testArrayIntersectUassoc(): void
1750+
{
1751+
$this->checkExplicitMixed = true;
1752+
$this->analyse([__DIR__ . '/data/array_intersect_uassoc.php'], [
1753+
[
1754+
'Parameter #3 $key_compare_func of function array_intersect_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1755+
22,
1756+
],
1757+
[
1758+
'Parameter #3 $key_compare_func of function array_intersect_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1759+
30,
1760+
],
1761+
]);
1762+
}
1763+
1764+
public function testArrayIntersectUkey(): void
1765+
{
1766+
$this->checkExplicitMixed = true;
1767+
$this->analyse([__DIR__ . '/data/array_intersect_ukey.php'], [
1768+
[
1769+
'Parameter #3 $key_compare_func of function array_intersect_ukey expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1770+
22,
1771+
],
1772+
[
1773+
'Parameter #3 $key_compare_func of function array_intersect_ukey expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1774+
30,
1775+
],
1776+
]);
1777+
}
1778+
1779+
public function testArrayUdiffAssoc(): void
1780+
{
1781+
$this->checkExplicitMixed = true;
1782+
$this->analyse([__DIR__ . '/data/array_udiff_assoc.php'], [
1783+
[
1784+
'Parameter #3 $key_comp_func of function array_udiff_assoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1785+
22,
1786+
],
1787+
[
1788+
'Parameter #3 $key_comp_func of function array_udiff_assoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1789+
30,
1790+
],
1791+
]);
1792+
}
1793+
1794+
public function testArrayUdiffUsssoc(): void
1795+
{
1796+
$this->checkExplicitMixed = true;
1797+
$this->analyse([__DIR__ . '/data/array_udiff_uassoc.php'], [
1798+
[
1799+
'Parameter #3 $data_comp_func of function array_udiff_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1800+
28,
1801+
],
1802+
[
1803+
'Parameter #4 $key_comp_func of function array_udiff_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1804+
31,
1805+
],
1806+
[
1807+
'Parameter #3 $data_comp_func of function array_udiff_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1808+
39,
1809+
],
1810+
[
1811+
'Parameter #4 $key_comp_func of function array_udiff_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1812+
42,
1813+
],
1814+
]);
1815+
}
1816+
1817+
public function testArrayUintersectAssoc(): void
1818+
{
1819+
$this->checkExplicitMixed = true;
1820+
$this->analyse([__DIR__ . '/data/array_uintersect_assoc.php'], [
1821+
[
1822+
'Parameter #3 $data_compare_func of function array_uintersect_assoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1823+
22,
1824+
],
1825+
[
1826+
'Parameter #3 $data_compare_func of function array_uintersect_assoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1827+
30,
1828+
],
1829+
]);
1830+
}
1831+
1832+
public function testArrayUintersectUassoc(): void
1833+
{
1834+
$this->checkExplicitMixed = true;
1835+
$this->analyse([__DIR__ . '/data/array_uintersect_uassoc.php'], [
1836+
[
1837+
'Parameter #3 $data_compare_func of function array_uintersect_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1838+
28,
1839+
],
1840+
[
1841+
'Parameter #4 $key_compare_func of function array_uintersect_uassoc expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1842+
31,
1843+
],
1844+
[
1845+
'Parameter #3 $data_compare_func of function array_uintersect_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1846+
39,
1847+
],
1848+
[
1849+
'Parameter #4 $key_compare_func of function array_uintersect_uassoc expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1850+
42,
1851+
],
1852+
]);
1853+
}
1854+
1855+
public function testArrayUintersect(): void
1856+
{
1857+
$this->checkExplicitMixed = true;
1858+
$this->analyse([__DIR__ . '/data/array_uintersect.php'], [
1859+
[
1860+
'Parameter #3 $data_compare_func of function array_uintersect expects callable(string, string): int<-1, 1>, Closure(int, int): int<-1, 1> given.',
1861+
22,
1862+
],
1863+
[
1864+
'Parameter #3 $data_compare_func of function array_uintersect expects callable(int, int): int<-1, 1>, Closure(string, string): int<-1, 1> given.',
1865+
30,
1866+
],
1867+
]);
1868+
}
1869+
17191870
public function testNoNamedArguments(): void
17201871
{
17211872
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)