Skip to content

Commit

Permalink
Fix argument type checking in function with func_get_args()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 11, 2020
1 parent 9774a8b commit 29a9882
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ static function (Type $type): bool {
}

$parameter = $parameters[count($parameters) - 1];
if (!$parameter->isVariadic()) {
break; // func_get_args
}
} else {
$parameter = $parameters[$i];
}
Expand Down
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,19 @@ public function testClassExists(): void
$this->analyse([__DIR__ . '/data/static-methods-class-exists.php'], []);
}

public function testBug3448(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-3448.php'], [
[
'Parameter #1 $lall of static method Bug3448\Foo::add() expects int, string given.',
21,
],
[
'Parameter #1 $lall of static method Bug3448\Foo::add() expects int, string given.',
22,
],
]);
}

}
24 changes: 24 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-3448.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Bug3448;

use function func_get_args;

final class Foo
{
public static function add(int $lall): void
{
$args = func_get_args();
}
}

final class UseFoo
{
public static function do(): void
{
Foo::add(1, [new \stdClass()]);

Foo::add('foo');
Foo::add('foo', [new \stdClass()]);
}
}

0 comments on commit 29a9882

Please sign in to comment.