Skip to content

Commit 25771ea

Browse files
[DependencyInjection] fix linting callable classes
1 parent 2b6a291 commit 25771ea

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

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)