Skip to content

Commit 4941982

Browse files
Understand at least one argument for non empty array unpacked
1 parent 2d8518a commit 4941982

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

src/Rules/FunctionCallParametersCheck.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ public function check(
188188
$arg->getStartLine(),
189189
];
190190
}
191+
192+
if (count($arguments) === 0 && $type->isIterableAtLeastOnce()->yes()) {
193+
$arguments[] = [
194+
$arg->value,
195+
$type->getIterableValueType(),
196+
true,
197+
null,
198+
$arg->getStartLine(),
199+
];
200+
}
191201
} else {
192202
$arguments[] = [
193203
$arg->value,

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,16 @@ public function testBug8922(): void
21692169
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-8922.php'], $errors);
21702170
}
21712171

2172+
public function testBug10020(): void
2173+
{
2174+
$this->analyse([__DIR__ . '/data/bug-10020.php'], []);
2175+
}
2176+
2177+
public function testBug8506(): void
2178+
{
2179+
$this->analyse([__DIR__ . '/data/bug-8506.php'], []);
2180+
}
2181+
21722182
public function testBug13065(): void
21732183
{
21742184
$errors = [];
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10020;
4+
5+
function load(string $path, string ...$extraPaths): void
6+
{
7+
//$this->doLoad(false, \func_get_args());
8+
}
9+
10+
$projectDir = __DIR__;
11+
$environment = 'dev';
12+
13+
$files = array_reverse(array_filter([
14+
$projectDir.'/.env',
15+
$projectDir.'/.env.'.$environment,
16+
$projectDir.'/.env.local',
17+
$projectDir.'/.env.'.$environment.'.local',
18+
], 'file_exists'));
19+
20+
if ($files !== []) {
21+
load(...$files);
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Bug8506;
4+
5+
function a(): ?int { return rand(0, 1) ? 1 : null; }
6+
function b(int $i, int ...$a): void {}
7+
8+
$arguments = array_filter([
9+
a(),
10+
a(),
11+
a(),
12+
]);
13+
14+
if (!$arguments) {
15+
return;
16+
}
17+
18+
b(...$arguments);

0 commit comments

Comments
 (0)