Skip to content

Commit 5422c7a

Browse files
authored
Make array_map argument take into account unpack
1 parent 66a2fd0 commit 5422c7a

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/Reflection/ParametersAcceptorSelector.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,20 @@ public static function selectFromArgs(
103103
$parameters = $acceptor->getParameters();
104104
$callbackParameters = [];
105105
foreach ($arrayMapArgs as $arg) {
106-
$callbackParameters[] = new DummyParameter('item', $scope->getIterableValueType($scope->getType($arg->value)), false, PassedByReference::createNo(), false, null);
106+
$argType = $scope->getType($arg->value);
107+
if ($arg->unpack) {
108+
$constantArrays = $argType->getConstantArrays();
109+
if (count($constantArrays) > 0) {
110+
foreach ($constantArrays as $constantArray) {
111+
$valueTypes = $constantArray->getValueTypes();
112+
foreach ($valueTypes as $valueType) {
113+
$callbackParameters[] = new DummyParameter('item', $scope->getIterableValueType($valueType), false, PassedByReference::createNo(), false, null);
114+
}
115+
}
116+
}
117+
} else {
118+
$callbackParameters[] = new DummyParameter('item', $scope->getIterableValueType($argType), false, PassedByReference::createNo(), false, null);
119+
}
107120
}
108121
$parameters[0] = new NativeParameterReflection(
109122
$parameters[0]->getName(),

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,15 @@ public function testDiscussion10454(): void
16271627
]);
16281628
}
16291629

1630+
public function testBug10527(): void
1631+
{
1632+
if (PHP_VERSION_ID < 70400) {
1633+
$this->markTestSkipped('Test requires PHP 7.4');
1634+
}
1635+
1636+
$this->analyse([__DIR__ . '/data/bug-10527.php'], []);
1637+
}
1638+
16301639
public function testBug10626(): void
16311640
{
16321641
$this->analyse([__DIR__ . '/data/bug-10626.php'], [
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug10527;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @param array{0: list<string>, 1: list<string>} $tuple
9+
*/
10+
public function sayHello(array $tuple): void
11+
{
12+
array_map(fn (string $first, string $second) => $first . $second, ...$tuple);
13+
}
14+
}

0 commit comments

Comments
 (0)