Skip to content

Commit 64618be

Browse files
committed
Fix overriden variadic parameter
1 parent 3950454 commit 64618be

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/Reflection/Php/PhpFunctionFromParserNodeReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private function getParameters(): array
151151
}
152152
$parameters[] = new PhpParameterFromParserNodeReflection(
153153
$parameter->var->name,
154-
$isOptional,
154+
$isOptional || $parameter->variadic,
155155
$this->realParameterTypes[$parameter->var->name],
156156
$this->phpDocParameterTypes[$parameter->var->name] ?? null,
157157
$parameter->byRef

tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\Php\PhpVersion;
66
use PHPStan\Rules\Rule;
77
use PHPStan\Testing\RuleTestCase;
8+
use const PHP_VERSION_ID;
89

910
/**
1011
* @extends RuleTestCase<OverridingMethodRule>
@@ -313,4 +314,10 @@ public function testParle(int $phpVersion, string $contravariantMessage, string
313314
]);
314315
}
315316

317+
public function testVariadicParameterIsAlwaysOptional(): void
318+
{
319+
$this->phpVersionId = PHP_VERSION_ID;
320+
$this->analyse([__DIR__ . '/data/variadic-always-optional.php'], []);
321+
}
322+
316323
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace VariadicParameterAlwaysOptional;
4+
5+
class Foo
6+
{
7+
8+
public function doFoo(string ...$test): void
9+
{
10+
11+
}
12+
13+
public function doBar(): void
14+
{
15+
16+
}
17+
18+
}
19+
20+
class Bar extends Foo
21+
{
22+
23+
public function doFoo(string ...$test): void
24+
{
25+
26+
}
27+
28+
public function doBar(...$test): void
29+
{
30+
31+
}
32+
33+
}

0 commit comments

Comments
 (0)