Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ public function check(
$arg->getStartLine(),
];
}

if (count($arguments) === 0 && $type->isIterableAtLeastOnce()->yes()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happen when the constant array is non-empty but all the keys are optional.

$arguments[] = [
$arg->value,
$type->getIterableValueType(),
true,
null,
$arg->getStartLine(),
];
}
} else {
$arguments[] = [
$arg->value,
Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,16 @@ public function testBug8922(): void
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-8922.php'], $errors);
}

public function testBug10020(): void
{
$this->analyse([__DIR__ . '/data/bug-10020.php'], []);
}

public function testBug8506(): void
{
$this->analyse([__DIR__ . '/data/bug-8506.php'], []);
}

public function testBug13065(): void
{
$errors = [];
Expand Down
22 changes: 22 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-10020.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace Bug10020;

function load(string $path, string ...$extraPaths): void
{
//$this->doLoad(false, \func_get_args());
}

$projectDir = __DIR__;
$environment = 'dev';

$files = array_reverse(array_filter([
$projectDir.'/.env',
$projectDir.'/.env.'.$environment,
$projectDir.'/.env.local',
$projectDir.'/.env.'.$environment.'.local',
], 'file_exists'));

if ($files !== []) {
load(...$files);
}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-8506.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Bug8506;

function a(): ?int { return rand(0, 1) ? 1 : null; }
function b(int $i, int ...$a): void {}

$arguments = array_filter([
a(),
a(),
a(),
]);

if (!$arguments) {
return;
}

b(...$arguments);
Loading