Skip to content

Commit db2675f

Browse files
committed
requires non-empty num
1 parent 8ae82c4 commit db2675f

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
@@ -2381,6 +2381,18 @@ public function testArrayRand(): void
23812381
'Parameter #1 $input of function array_rand expects non-empty-array, array{} given.',
23822382
8,
23832383
'array{} is empty.'
2384+
],
2385+
[
2386+
'Parameter #2 $num_req of function array_rand expects int<1, max>, int given.',
2387+
8,
2388+
],
2389+
[
2390+
'Parameter #2 $num_req of function array_rand expects int<1, max>, -5 given.',
2391+
13,
2392+
],
2393+
[
2394+
'Parameter #2 $num_req of function array_rand expects int<1, max>, 0 given.',
2395+
14,
23842396
]
23852397
]);
23862398
}

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)