Skip to content

Commit 785b3cc

Browse files
committed
cover analog \Random\Randomizer::pickArrayKeys() method
1 parent 5856e00 commit 785b3cc

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
@@ -2371,16 +2371,16 @@ public function testBug13556(): void
23712371
#[RequiresPhp('>= 8.0')]
23722372
public function testArrayRand(): void
23732373
{
2374-
$this->analyse([__DIR__ . '/data/array-rand.php'], [
2374+
$this->analyse([__DIR__ . '/data/array_rand.php'], [
23752375
[
23762376
'Parameter #1 $input of function array_rand expects non-empty-array, array{} given.',
23772377
7,
2378-
'array{} is empty.'
2378+
'array{} is empty.',
23792379
],
23802380
[
23812381
'Parameter #1 $input of function array_rand expects non-empty-array, array{} given.',
23822382
8,
2383-
'array{} is empty.'
2383+
'array{} is empty.',
23842384
],
23852385
[
23862386
'Parameter #2 $num_req of function array_rand expects int<1, max>, int given.',
@@ -2393,14 +2393,14 @@ public function testArrayRand(): void
23932393
[
23942394
'Parameter #2 $num_req of function array_rand expects int<1, max>, 0 given.',
23952395
14,
2396-
]
2396+
],
23972397
]);
23982398
}
23992399

24002400
#[RequiresPhp('< 8.0')]
24012401
public function testArrayRandPhp7(): void
24022402
{
2403-
$this->analyse([__DIR__ . '/data/array-rand.php'], []);
2403+
$this->analyse([__DIR__ . '/data/array_rand.php'], []);
24042404
}
24052405

24062406
}

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)