Skip to content

[DI] Skip unknown method calls for factories in check types pass #34562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,24 +38,22 @@ 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);
}

/**
* {@inheritdoc}
*/
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);
}

Expand All @@ -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]);
}
Expand Down