From 592bff88f250d1756d35414362282a2dea0e88c9 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Sun, 24 Nov 2019 00:18:37 +0100 Subject: [PATCH] [DI] Skip unknown method calls for factories in check types pass --- .../Functional/Bundle/TestBundle/TestBundle.php | 2 +- .../Bundle/FrameworkBundle/composer.json | 2 +- .../Compiler/CheckTypeDeclarationsPass.php | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestBundle.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestBundle.php index d0fb6ee0daa2..db4b2504aa3e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestBundle.php @@ -49,6 +49,6 @@ public function process(ContainerBuilder $container) } }); - $container->addCompilerPass(new CheckTypeDeclarationsPass(true, ['http_client', '.debug.http_client']), PassConfig::TYPE_AFTER_REMOVING, -100); + $container->addCompilerPass(new CheckTypeDeclarationsPass(true), PassConfig::TYPE_AFTER_REMOVING, -100); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 7022e25a21b8..bbddc40ca776 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -20,7 +20,7 @@ "ext-xml": "*", "symfony/cache": "^4.4|^5.0", "symfony/config": "^4.3.4|^5.0", - "symfony/dependency-injection": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4.1|^5.0.1", "symfony/http-foundation": "^4.4|^5.0", "symfony/http-kernel": "^4.4", "symfony/polyfill-mbstring": "~1.0", diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php index 2147d53f1263..213bcf1313ba 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php @@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Parameter; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; @@ -37,16 +38,14 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass private const SCALAR_TYPES = ['int', 'float', 'bool', 'string']; private $autoload; - private $ignoredServices; /** * @param bool $autoload Whether services who's class in not loaded should be checked or not. * Defaults to false to save loading code during compilation. */ - public function __construct(bool $autoload = false, array $ignoredServices = []) + public function __construct(bool $autoload = false) { $this->autoload = $autoload; - $this->ignoredServices = array_flip($ignoredServices); } /** @@ -54,7 +53,7 @@ public function __construct(bool $autoload = false, array $ignoredServices = []) */ protected function processValue($value, $isRoot = false) { - if (!$value instanceof Definition || isset($this->ignoredServices[$this->currentId])) { + if (!$value instanceof Definition || $value->hasErrors()) { return parent::processValue($value, $isRoot); } @@ -71,7 +70,15 @@ protected function processValue($value, $isRoot = false) } foreach ($value->getMethodCalls() as $methodCall) { - $reflectionMethod = $this->getReflectionMethod($value, $methodCall[0]); + try { + $reflectionMethod = $this->getReflectionMethod($value, $methodCall[0]); + } catch (RuntimeException $e) { + if ($value->getFactory()) { + continue; + } + + throw $e; + } $this->checkTypeDeclarations($value, $reflectionMethod, $methodCall[1]); }