Skip to content

Commit

Permalink
PhpFunctionFromParserNodeReflection - fix optionality of parameters w…
Browse files Browse the repository at this point in the history
…ith default value followed by variadic parmaeters
  • Loading branch information
ondrejmirtes committed Jun 11, 2020
1 parent e36d163 commit e00262d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Reflection/Php/PhpFunctionFromParserNodeReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private function getParameters(): array

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

Expand All @@ -151,7 +151,7 @@ private function getParameters(): array
}
$parameters[] = new PhpParameterFromParserNodeReflection(
$parameter->var->name,
$isOptional || $parameter->variadic,
$isOptional,
$this->realParameterTypes[$parameter->var->name],
$this->phpDocParameterTypes[$parameter->var->name] ?? null,
$parameter->byRef
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,10 @@ public function testBug3403(int $phpVersion): void
$this->analyse([__DIR__ . '/data/bug-3403.php'], []);
}

public function testBug3443(): void
{
$this->phpVersionId = PHP_VERSION_ID;
$this->analyse([__DIR__ . '/data/bug-3443.php'], []);
}

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

namespace Bug3443;

/**
* Interface Collection.
*/
interface CollectionInterface
{

/**
* @param mixed $data
* @param mixed ...$parameters
*
* @return mixed
*/
public static function with($data = [], ...$parameters);

}


/**
* Class Collection.
*/
final class Collection implements CollectionInterface
{

public static function with($data = [], ...$parameters)
{
return new self();
}

}

0 comments on commit e00262d

Please sign in to comment.