Skip to content

Commit e00262d

Browse files
committed
PhpFunctionFromParserNodeReflection - fix optionality of parameters with default value followed by variadic parmaeters
1 parent e36d163 commit e00262d

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/Reflection/Php/PhpFunctionFromParserNodeReflection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private function getParameters(): array
142142

143143
/** @var \PhpParser\Node\Param $parameter */
144144
foreach (array_reverse($this->functionLike->getParams()) as $parameter) {
145-
if (!$isOptional || $parameter->default === null) {
145+
if ($parameter->default === null && !$parameter->variadic) {
146146
$isOptional = false;
147147
}
148148

@@ -151,7 +151,7 @@ private function getParameters(): array
151151
}
152152
$parameters[] = new PhpParameterFromParserNodeReflection(
153153
$parameter->var->name,
154-
$isOptional || $parameter->variadic,
154+
$isOptional,
155155
$this->realParameterTypes[$parameter->var->name],
156156
$this->phpDocParameterTypes[$parameter->var->name] ?? null,
157157
$parameter->byRef

tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,10 @@ public function testBug3403(int $phpVersion): void
330330
$this->analyse([__DIR__ . '/data/bug-3403.php'], []);
331331
}
332332

333+
public function testBug3443(): void
334+
{
335+
$this->phpVersionId = PHP_VERSION_ID;
336+
$this->analyse([__DIR__ . '/data/bug-3443.php'], []);
337+
}
338+
333339
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Bug3443;
4+
5+
/**
6+
* Interface Collection.
7+
*/
8+
interface CollectionInterface
9+
{
10+
11+
/**
12+
* @param mixed $data
13+
* @param mixed ...$parameters
14+
*
15+
* @return mixed
16+
*/
17+
public static function with($data = [], ...$parameters);
18+
19+
}
20+
21+
22+
/**
23+
* Class Collection.
24+
*/
25+
final class Collection implements CollectionInterface
26+
{
27+
28+
public static function with($data = [], ...$parameters)
29+
{
30+
return new self();
31+
}
32+
33+
}

0 commit comments

Comments
 (0)