Skip to content

Commit 4ebeb89

Browse files
committed
bug symfony#44710 [DependencyInjection] fix linting callable classes (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] fix linting callable classes | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#44356 | License | MIT | Doc PR | - Commits ------- 87097b8 [DependencyInjection] fix linting callable classes
2 parents f2cac74 + 87097b8 commit 4ebeb89

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ protected function getReflectionMethod(Definition $definition, $method)
203203
}
204204

205205
if (!$r->hasMethod($method)) {
206+
if ($r->hasMethod('__call') && ($r = $r->getMethod('__call')) && $r->isPublic()) {
207+
return new \ReflectionMethod(static function (...$arguments) {}, '__invoke');
208+
}
209+
206210
throw new RuntimeException(sprintf('Invalid service "%s": method "%s()" does not exist.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
207211
}
208212

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,4 +988,22 @@ public function testIntersectionTypeFailsWithReference()
988988

989989
(new CheckTypeDeclarationsPass(true))->process($container);
990990
}
991+
992+
public function testCallableClass()
993+
{
994+
$container = new ContainerBuilder();
995+
$definition = $container->register('foo', CallableClass::class);
996+
$definition->addMethodCall('callMethod', [123]);
997+
998+
(new CheckTypeDeclarationsPass())->process($container);
999+
1000+
$this->addToAssertionCount(1);
1001+
}
1002+
}
1003+
1004+
class CallableClass
1005+
{
1006+
public function __call($name, $arguments)
1007+
{
1008+
}
9911009
}

0 commit comments

Comments
 (0)