Skip to content

Commit 4f42799

Browse files
committed
requires non-empty num
1 parent 3c62bf6 commit 4f42799

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

resources/functionMap_php80delta_bleedingEdge.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
return [
44
'new' => [
5-
'array_rand' => ['int|string|array<int,int>|array<int,string>', 'input'=>'non-empty-array', 'num_req'=>'int'],
5+
'array_rand' => ['int|string|array<int,int>|array<int,string>', 'input'=>'non-empty-array', 'num_req'=>'positive-int'],
66
'array_rand\'1' => ['int|string', 'input'=>'non-empty-array'],
77
],
88
'old' => [
9-
'array_rand' => ['int|string|array<int,int>|array<int,string>', 'input'=>'array', 'num_req'=>'int'],
9+
'array_rand' => ['int|string|array<int,int>|array<int,string>', 'input'=>'array', 'num_req'=>'positive-int'],
1010
'array_rand\'1' => ['int|string', 'input'=>'array'],
1111
],
1212
];

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,18 @@ public function testArrayRand(): void
23442344
'Parameter #1 $input of function array_rand expects non-empty-array, array{} given.',
23452345
8,
23462346
'array{} is empty.'
2347+
],
2348+
[
2349+
'Parameter #2 $num_req of function array_rand expects int<1, max>, int given.',
2350+
8,
2351+
],
2352+
[
2353+
'Parameter #2 $num_req of function array_rand expects int<1, max>, -5 given.',
2354+
13,
2355+
],
2356+
[
2357+
'Parameter #2 $num_req of function array_rand expects int<1, max>, 0 given.',
2358+
14,
23472359
]
23482360
]);
23492361
}

tests/PHPStan/Rules/Functions/data/array-rand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ function doFoo(int $i) {
77
$x = array_rand($arr);
88
$y = array_rand($arr, $i);
99
}
10+
11+
/** @param non-empty-array $arr */
12+
function doBar(array $arr) {
13+
$y = array_rand($arr, -5);
14+
$y = array_rand($arr, 0);
15+
$y = array_rand($arr, 1);
16+
$y = array_rand($arr);
17+
}

0 commit comments

Comments
 (0)