Skip to content

Commit 8596663

Browse files
committed
Regression tests
Closes phpstan/phpstan#5356 Closes phpstan/phpstan#1954
1 parent 3e0ecec commit 8596663

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -843,4 +843,32 @@ public function testArrayMapMultiple(bool $checkExplicitMixed): void
843843
]);
844844
}
845845

846+
public function testBug5356(): void
847+
{
848+
if (PHP_VERSION_ID < 70400 && !self::$useStaticReflectionProvider) {
849+
$this->markTestSkipped('Test requires PHP 7.4.');
850+
}
851+
852+
$this->analyse([__DIR__ . '/data/bug-5356.php'], [
853+
[
854+
'Parameter #1 $callback of function array_map expects callable(string): mixed, Closure(array): \'a\' given.',
855+
13,
856+
],
857+
[
858+
'Parameter #1 $callback of function array_map expects callable(string): mixed, Closure(array): \'a\' given.',
859+
21,
860+
],
861+
]);
862+
}
863+
864+
public function testBug1954(): void
865+
{
866+
$this->analyse([__DIR__ . '/data/bug-1954.php'], [
867+
[
868+
'Parameter #1 $callback of function array_map expects callable(1|stdClass): mixed, Closure(string): string given.',
869+
7,
870+
],
871+
]);
872+
}
873+
846874
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Bug1954;
4+
5+
function (): void {
6+
$a = [1, new \stdClass()];
7+
$b = array_map(function (string $s) : string { return $s; }, $a);
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php // lint >= 7.4
2+
3+
namespace Bug5356;
4+
5+
class Foo
6+
{
7+
8+
public function doFoo(): void
9+
{
10+
/** @var array{name: string, collectors: string[]} $array */
11+
$array = [];
12+
13+
array_map(static fn(array $_): string => 'a', $array['collectors']);
14+
}
15+
16+
public function doBar(): void
17+
{
18+
/** @var array{name: string, collectors: string[]} $array */
19+
$array = [];
20+
21+
array_map(static function(array $_): string { return 'a'; }, $array['collectors']);
22+
}
23+
24+
}

0 commit comments

Comments
 (0)