diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 419965a1ae0..c74048d3e62 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -858,4 +858,32 @@ public function testArrayMapMultiple(bool $checkExplicitMixed): void ]); } + public function testBug5356(): void + { + if (PHP_VERSION_ID < 70400 && !self::$useStaticReflectionProvider) { + $this->markTestSkipped('Test requires PHP 7.4.'); + } + + $this->analyse([__DIR__ . '/data/bug-5356.php'], [ + [ + 'Parameter #1 $callback of function array_map expects callable(string): mixed, Closure(array): \'a\' given.', + 13, + ], + [ + 'Parameter #1 $callback of function array_map expects callable(string): mixed, Closure(array): \'a\' given.', + 21, + ], + ]); + } + + public function testBug1954(): void + { + $this->analyse([__DIR__ . '/data/bug-1954.php'], [ + [ + 'Parameter #1 $callback of function array_map expects callable(1|stdClass): mixed, Closure(string): string given.', + 7, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-1954.php b/tests/PHPStan/Rules/Functions/data/bug-1954.php new file mode 100644 index 00000000000..38e4354cbcd --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-1954.php @@ -0,0 +1,8 @@ += 7.4 + +namespace Bug5356; + +class Foo +{ + + public function doFoo(): void + { + /** @var array{name: string, collectors: string[]} $array */ + $array = []; + + array_map(static fn(array $_): string => 'a', $array['collectors']); + } + + public function doBar(): void + { + /** @var array{name: string, collectors: string[]} $array */ + $array = []; + + array_map(static function(array $_): string { return 'a'; }, $array['collectors']); + } + +}