Skip to content

Commit ceb9a3d

Browse files
committed
cover analog \Random\Randomizer::pickArrayKeys() method
1 parent 380b4bd commit ceb9a3d

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

resources/functionMap_php82delta.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'iterator_count' => ['0|positive-int', 'iterator'=>'iterable'],
2525
'iterator_to_array' => ['array', 'iterator'=>'iterable', 'use_keys='=>'bool'],
2626
'str_split' => ['list<string>', 'str'=>'string', 'split_length='=>'positive-int'],
27+
'Random\Randomizer::pickArrayKeys' => ['non-empty-array<int|string>', 'array'=>'non-empty-array', 'num'=>'positive-int'],
2728
],
2829
'old' => [
2930

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,16 +2334,16 @@ public function testBug13556(): void
23342334
#[RequiresPhp('>= 8.0')]
23352335
public function testArrayRand(): void
23362336
{
2337-
$this->analyse([__DIR__ . '/data/array-rand.php'], [
2337+
$this->analyse([__DIR__ . '/data/array_rand.php'], [
23382338
[
23392339
'Parameter #1 $input of function array_rand expects non-empty-array, array{} given.',
23402340
7,
2341-
'array{} is empty.'
2341+
'array{} is empty.',
23422342
],
23432343
[
23442344
'Parameter #1 $input of function array_rand expects non-empty-array, array{} given.',
23452345
8,
2346-
'array{} is empty.'
2346+
'array{} is empty.',
23472347
],
23482348
[
23492349
'Parameter #2 $num_req of function array_rand expects int<1, max>, int given.',
@@ -2356,14 +2356,14 @@ public function testArrayRand(): void
23562356
[
23572357
'Parameter #2 $num_req of function array_rand expects int<1, max>, 0 given.',
23582358
14,
2359-
]
2359+
],
23602360
]);
23612361
}
23622362

23632363
#[RequiresPhp('< 8.0')]
23642364
public function testArrayRandPhp7(): void
23652365
{
2366-
$this->analyse([__DIR__ . '/data/array-rand.php'], []);
2366+
$this->analyse([__DIR__ . '/data/array_rand.php'], []);
23672367
}
23682368

23692369
}
File renamed without changes.

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3675,4 +3675,25 @@ public function testBug13511(): void
36753675
$this->analyse([__DIR__ . '/data/bug-13511.php'], []);
36763676
}
36773677

3678+
#[RequiresPhp('>= 8.2')]
3679+
public function testRandomizer(): void
3680+
{
3681+
$this->checkThisOnly = false;
3682+
$this->checkNullables = true;
3683+
$this->checkUnionTypes = true;
3684+
$this->checkExplicitMixed = true;
3685+
3686+
$this->analyse([__DIR__ . '/data/randomizer.php'], [
3687+
[
3688+
'Parameter #2 $num of method Random\Randomizer::pickArrayKeys() expects int<1, max>, 0 given.',
3689+
7,
3690+
],
3691+
[
3692+
'Parameter #1 $array of method Random\Randomizer::pickArrayKeys() expects non-empty-array, array{} given.',
3693+
8,
3694+
'array{} is empty.',
3695+
],
3696+
]);
3697+
}
3698+
36783699
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Randomizer;
4+
5+
$r = new \Random\Randomizer();
6+
var_dump($r->pickArrayKeys(['a', 'b'], 10));
7+
var_dump($r->pickArrayKeys(['a'], 0));
8+
var_dump($r->pickArrayKeys([], 1));

0 commit comments

Comments
 (0)