8000 fix check miss on variadic · symfony/symfony@83d05b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 83d05b8

Browse files
committed
fix check miss on variadic
1 parent b563760 commit 83d05b8

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeHintsPass.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,8 @@ private function checkArgumentsTypeHints(\ReflectionFunctionAbstract $reflection
8282
$reflectionParameters = $reflectionFunction->getParameters();
8383
$checksCount = min($reflectionFunction->getNumberOfParameters(), count($configurationArguments));
8484

85-
if ($reflectionFunction->isVariadic()) {
86-
--$checksCount;
87-
}
88-
8985
for ($i = 0; $i < $checksCount; ++$i) {
90-
if (!$reflectionParameters[$i]->hasType()) {
86+
if (!$reflectionParameters[$i]->hasType() || $reflectionParameters[$i]->isVariadic()) {
9187
continue;
9288
}
9389

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeHintsPassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@ public function testProcessVariadicFails()
145145
(new CheckTypeHintsPass(true))->process($container);
146146
}
147147

148+
/**
149+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
150+
* @expectedExceptionMessage Invalid definition for service "bar": argument 0 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeHintsPass\BarMethodCall::setFoosVariadic" requires a "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeHintsPass\Foo", "stdClass" passed
151+
*/
152+
public function testProcessVariadicFailsOnPassingBadTypeOnAnotherArgument()
153+
{
154+
$container = new ContainerBuilder();
155+
156+
$container->register('stdClass', \stdClass::class);
157+
$container->register('foo', Foo::class);
158+
$container->register('bar', BarMethodCall::class)
159+
->addMethodCall('setFoosVariadic', array(
160+
new Reference('stdClass'),
161+
));
162+
163+
(new CheckTypeHintsPass(true))->process($container);
164+
}
165+
148166
public function testProcessVariadicSuccess()
149167
{
150168
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)
0