8000 [DependencyInjection] Fix linting factories implemented via __callStatic · symfony/symfony@e2f69af · GitHub
[go: up one dir, main page]

Skip to content

Commit e2f69af

Browse files
KevinVanSonsbeeknicolas-grekas
authored andcommitted
[DependencyInjection] Fix linting factories implemented via __callStatic
1 parent ebd2270 commit e2f69af

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
@@ -202,6 +202,10 @@ protected function getReflectionMethod(Definition $definition, string $method)
202202
return new \ReflectionMethod(static function (...$arguments) {}, '__invoke');
203203
}
204204

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,17 @@ public function testCallableClass()
10151015
$this->addToAssertionCount(1);
10161016
}
10171017

1018+
public function testStaticCallableClass()
1019+
{
1020+
$container = new ContainerBuilder();
1021+
$container->register('foo', StaticCallableClass::class)
1022+
->setFactory([StaticCallableClass::class, 'staticMethodCall']);
1023+
1024+
(new CheckTypeDeclarationsPass())->process($container);
1025+
1026+
$this->addToAssertionCount(1);
1027+
}
1028+
10181029
public function testIgnoreDefinitionFactoryArgument()
10191030
{
10201031
$container = new ContainerBuilder();
@@ -1050,3 +1061,10 @@ public function __call($name, $arguments)
10501061
{
10511062
}
10521063
}
1064+
1065+
class StaticCallableClass
1066+
{
1067+
public static function __callStatic($name, $arguments)
1068+
{
1069+
}
1070+
}

0 commit comments

Comments
 (0)
155B
0