Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ private function checkTypeDeclarations(Definition $checkedDefinition, \Reflectio
if (!$p->hasType() || $p->isVariadic()) {
continue;
}
$key = $i;
if (\array_key_exists($p->name, $values)) {
$i = $p->name;
$key = $p->name;
} elseif (!\array_key_exists($i, $values)) {
continue;
}

$this->checkType($checkedDefinition, $values[$i], $p, $envPlaceholderUniquePrefix);
$this->checkType($checkedDefinition, $values[$key], $p, $envPlaceholderUniquePrefix);
}

if ($reflectionFunction->isVariadic() && ($lastParameter = end($reflectionParameters))->hasType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,18 @@ public function testErroredDefinitionsAreNotChecked()

$this->addToAssertionCount(1);
}

public function testCheckTypeDeclarationsSkipsSubsequentNamedArguments()
{
$container = new ContainerBuilder();
$container->register('service', ServiceWithTwoInts::class)
->setArguments(['a' => 1, 'b' => []]);

$this->expectException(InvalidParameterTypeException::class);
$this->expectExceptionMessage('argument 2 of "Symfony\Component\DependencyInjection\Tests\Compiler\ServiceWithTwoInts::__construct()" accepts "int", "array" passed');

(new CheckTypeDeclarationsPass(true))->process($container);
}
}

class CallableClass
Expand All @@ -1038,3 +1050,10 @@ public static function __callStatic($name, $arguments)
{
}
}

class ServiceWithTwoInts
{
public function __construct(int $a, int $b)
{
}
}