Skip to content

Commit 9a64b3f

Browse files
bug #34562 [DI] Skip unknown method calls for factories in check types pass (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [DI] Skip unknown method calls for factories in check types pass | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | symfony/symfony#34559 | License | MIT | Doc PR | - Ref symfony/symfony#30885 and symfony/symfony#30889. Commits ------- 592bff88f2 [DI] Skip unknown method calls for factories in check types pass
2 parents 22acc95 + 5e02e69 commit 9a64b3f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Compiler/CheckTypeDeclarationsPass.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\Definition;
1717
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1818
use Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException;
19+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1920
use Symfony\Component\DependencyInjection\Parameter;
2021
use Symfony\Component\DependencyInjection\Reference;
2122
use Symfony\Component\DependencyInjection\ServiceLocator;
@@ -37,24 +38,22 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
3738
private const SCALAR_TYPES = ['int', 'float', 'bool', 'string'];
3839

3940
private $autoload;
40-
private $ignoredServices;
4141

4242
/**
4343
* @param bool $autoload Whether services who's class in not loaded should be checked or not.
4444
* Defaults to false to save loading code during compilation.
4545
*/
46-
public function __construct(bool $autoload = false, array $ignoredServices = [])
46+
public function __construct(bool $autoload = false)
4747
{
4848
$this->autoload = $autoload;
49-
$this->ignoredServices = array_flip($ignoredServices);
5049
}
5150

5251
/**
5352
* {@inheritdoc}
5453
*/
5554
protected function processValue($value, $isRoot = false)
5655
{
57-
if (!$value instanceof Definition || isset($this->ignoredServices[$this->currentId])) {
56+
if (!$value instanceof Definition || $value->hasErrors()) {
5857
return parent::processValue($value, $isRoot);
5958
}
6059

@@ -71,7 +70,15 @@ protected function processValue($value, $isRoot = false)
7170
}
7271

7372
foreach ($value->getMethodCalls() as $methodCall) {
74-
$reflectionMethod = $this->getReflectionMethod($value, $methodCall[0]);
73+
try {
74+
$reflectionMethod = $this->getReflectionMethod($value, $methodCall[0]);
75+
} catch (RuntimeException $e) {
76+
if ($value->getFactory()) {
77+
continue;
78+
}
79+
80+
throw $e;
81+
}
7582

7683
$this->checkTypeDeclarations($value, $reflectionMethod, $methodCall[1]);
7784
}

0 commit comments

Comments
 (0)