Skip to content

Commit

Permalink
Fix overriden variadic parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 7, 2020
1 parent 3950454 commit 64618be
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Reflection/Php/PhpFunctionFromParserNodeReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private function getParameters(): array
}
$parameters[] = new PhpParameterFromParserNodeReflection(
$parameter->var->name,
$isOptional,
$isOptional || $parameter->variadic,
$this->realParameterTypes[$parameter->var->name],
$this->phpDocParameterTypes[$parameter->var->name] ?? null,
$parameter->byRef
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPStan\Php\PhpVersion;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;

/**
* @extends RuleTestCase<OverridingMethodRule>
Expand Down Expand Up @@ -313,4 +314,10 @@ public function testParle(int $phpVersion, string $contravariantMessage, string
]);
}

public function testVariadicParameterIsAlwaysOptional(): void
{
$this->phpVersionId = PHP_VERSION_ID;
$this->analyse([__DIR__ . '/data/variadic-always-optional.php'], []);
}

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

namespace VariadicParameterAlwaysOptional;

class Foo
{

public function doFoo(string ...$test): void
{

}

public function doBar(): void
{

}

}

class Bar extends Foo
{

public function doFoo(string ...$test): void
{

}

public function doBar(...$test): void
{

}

}

0 comments on commit 64618be

Please sign in to comment.