8000 add missing case with 'iterable' type hint · symfony/symfony@3e9c37d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e9c37d

Browse files
committed
add missing case with 'iterable' type hint
1 parent 1aefc17 commit 3e9c37d

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\Reference;
1616
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1717
use Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeHintException;
18+
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1819

1920
/**
2021
* Checks whether injected parameters types are compatible with type hints.
@@ -137,6 +138,10 @@ private function checkTypeHint($configurationArgument, \ReflectionParameter $par
137138
return;
138139
}
139140

141+
if ($parameter->getType()->getName() === 'iterable' && $configurationArgument instanceof IteratorArgument) {
142+
return;
143+
}
144+
140145
$checkFunction = 'is_'.$parameter->getType()->getName();
141146

142147
if (!$parameter->getType()->isBuiltin() || !$checkFunction($configurationArgument)) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1718
use Symfony\Component\DependencyInjection\Compiler\CheckTypeHintsPass;
1819
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeHintsPass\Bar;
1920
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeHintsPass\BarOptionalArgument;
@@ -399,6 +400,20 @@ public function testProcessSuccessWhenPassingIntegerToArrayTypeHintedParameter()
399400
$this->addToAssertionCount(1);
400401
}
401402

403+
public function testProcessSuccessWhenPassingAnIteratorArgumentToIterable()
404+
{
405+
$container = new ContainerBuilder();
406+
407+
$container->register('bar', BarMethodCall::class)
408+
->addMethodCall('setIterable', array(
409+
new IteratorArgument(array()),
410+
));
411+
412+
(new CheckTypeHintsPass(true))->process($container);
413+
414+
$this->addToAssertionCount(1);
415+
}
416+
402417
public function testProcessFactory()
403418
{
404419
$container = new ContainerBuilder();

src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeHintsPass/BarMethodCall.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ public function setScalars(int $int, string $string, bool $bool = false)
2828
public function setArray(array $array)
2929
{
3030
}
31+
32+
public function setIterable(iterable $iterable)
33+
{
34+
}
3135
}

0 commit comments

Comments
 (0)
0