diff --git a/Compiler/AbstractRecursivePass.php b/Compiler/AbstractRecursivePass.php index f7a2176eb..b990ad828 100644 --- a/Compiler/AbstractRecursivePass.php +++ b/Compiler/AbstractRecursivePass.php @@ -202,6 +202,10 @@ protected function getReflectionMethod(Definition $definition, string $method) return new \ReflectionMethod(static function (...$arguments) {}, '__invoke'); } + if ($r->hasMethod('__callStatic') && ($r = $r->getMethod('__callStatic')) && $r->isPublic()) { + return new \ReflectionMethod(static function (...$arguments) {}, '__invoke'); + } + throw new RuntimeException(sprintf('Invalid service "%s": method "%s()" does not exist.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method)); } diff --git a/Tests/Compiler/CheckTypeDeclarationsPassTest.php b/Tests/Compiler/CheckTypeDeclarationsPassTest.php index 90a5248f1..9101f7fb5 100644 --- a/Tests/Compiler/CheckTypeDeclarationsPassTest.php +++ b/Tests/Compiler/CheckTypeDeclarationsPassTest.php @@ -1015,6 +1015,17 @@ public function testCallableClass() $this->addToAssertionCount(1); } + public function testStaticCallableClass() + { + $container = new ContainerBuilder(); + $container->register('foo', StaticCallableClass::class) + ->setFactory([StaticCallableClass::class, 'staticMethodCall']); + + (new CheckTypeDeclarationsPass())->process($container); + + $this->addToAssertionCount(1); + } + public function testIgnoreDefinitionFactoryArgument() { $container = new ContainerBuilder(); @@ -1050,3 +1061,10 @@ public function __call($name, $arguments) { } } + +class StaticCallableClass +{ + public static function __callStatic($name, $arguments) + { + } +}