Skip to content

Commit

Permalink
bug #34562 [DI] Skip unknown method calls for factories in check type…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
nicolas-grekas committed Nov 28, 2019
2 parents 22acc95 + 5e02e69 commit 9a64b3f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Compiler/CheckTypeDeclarationsPass.php
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

0 comments on commit 9a64b3f

Please sign in to comment.