Skip to content

Commit e6629a4

Browse files
martijnboersruudk
authored andcommitted
Output class in exception when AutoRegister fails
When a public class that is wrongly configured or misplaced fails, it's hard to debug. This is because it will fail because of a `getName()` function call on a null object. To improve developer experience, output the classname it fails on.
1 parent 8ca920f commit e6629a4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/DependencyInjection/Compiler/AutoRegister.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SimpleBus\SymfonyBridge\DependencyInjection\Compiler;
44

5+
use RuntimeException;
56
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
67
use Symfony\Component\DependencyInjection\ContainerBuilder;
78

@@ -58,6 +59,11 @@ public function process(ContainerBuilder $container)
5859
continue;
5960
}
6061

62+
if ($parameters[0]->getClass() === null) {
63+
throw new RuntimeException(sprintf('Could not get auto register class %s because the first parameter %s of public method %s should be have a class typehint. Either specify the typehint, make the function non-public, or disable auto registration.', $method->class,
64+
$parameters[0]->getName(), $method->getName()));
65+
}
66+
6167
// get the class name
6268
$handles = $parameters[0]->getClass()->getName();
6369

0 commit comments

Comments
 (0)