Skip to content

Commit ac23ecd

Browse files
committed
array_filter test
1 parent 21f6804 commit ac23ecd

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,36 @@ public function testArrayMapMultiple(bool $checkExplicitMixed): void
843843
]);
844844
}
845845

846+
public function dataArrayFilterCallback(): array
847+
{
848+
return [
849+
[true],
850+
[false],
851+
];
852+
}
853+
854+
/**
855+
* @dataProvider dataArrayFilterCallback
856+
* @param bool $checkExplicitMixed
857+
*/
858+
public function testArrayFilterCallback(bool $checkExplicitMixed): void
859+
{
860+
$this->checkExplicitMixed = $checkExplicitMixed;
861+
$errors = [
862+
[
863+
'Parameter #2 $callback of function array_filter expects callable(int): mixed, Closure(string): true given.',
864+
17,
865+
],
866+
];
867+
if ($checkExplicitMixed) {
868+
$errors[] =[
869+
'Parameter #2 $callback of function array_filter expects callable(mixed): mixed, Closure(int): true given.',
870+
20,
871+
];
872+
}
873+
$this->analyse([__DIR__ . '/data/array_filter_callback.php'], $errors);
874+
}
875+
846876
public function testBug5356(): void
847877
{
848878
if (PHP_VERSION_ID < 70400 && !self::$useStaticReflectionProvider) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace ArrayFilterCallback;
4+
5+
class Foo
6+
{
7+
8+
/**
9+
* @param int[] $ints
10+
* @param mixed[] $mixeds
11+
*/
12+
public function doFoo(array $ints, array $mixeds): void
13+
{
14+
array_filter($ints, function (int $i): bool {
15+
return true;
16+
});
17+
array_filter($ints, function (string $i): bool {
18+
return true;
19+
});
20+
array_filter($mixeds, function (int $i): bool {
21+
return true;
22+
});
23+
}
24+
25+
}

0 commit comments

Comments
 (0)